-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
282 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: "Builtins: builtin" | ||
cases: | ||
- name: "builtin with no builtin" | ||
stdin: builtin | ||
|
||
- name: "builtin with unknown builtin" | ||
ignore_stderr: true | ||
stdin: builtin not-a-builtin args | ||
|
||
- name: "valid builtin" | ||
stdin: builtin echo "Hello world" | ||
|
||
- name: "valid builtin with hyphen args" | ||
stdin: builtin echo -e "Hello\nWorld" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: "Builtins: let" | ||
cases: | ||
- name: "Basic let usage" | ||
stdin: | | ||
let 0; echo "0 => $?" | ||
let 1; echo "1 => $?" | ||
let 0==0; echo "0==0 => $?" | ||
let 0!=0; echo "0!=0 => $?" | ||
let 1 0; echo "1 0 => $?" | ||
let 0 1; echo "0 1 => $?" | ||
- name: "let with assignment" | ||
stdin: | | ||
let x=10; echo "x=10 => $?; x==${x}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: "Builtins: readonly" | ||
cases: | ||
- name: "making var readonly" | ||
stdin: | | ||
my_var="value" | ||
readonly my_var | ||
echo "Invoking declare -p..." | ||
declare -p my_var | ||
- name: "using readonly with value" | ||
stdin: | | ||
readonly my_var="my_value" | ||
echo "Invoking declare -p..." | ||
declare -p my_var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use clap::Parser; | ||
use std::io::Write; | ||
|
||
use crate::{ | ||
builtin::{BuiltinCommand, BuiltinExitCode}, | ||
commands, | ||
}; | ||
|
||
#[derive(Parser)] | ||
pub(crate) struct BuiltiCommand { | ||
builtin_name: Option<String>, | ||
|
||
#[arg(trailing_var_arg = true, allow_hyphen_values = true)] | ||
args: Vec<String>, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl BuiltinCommand for BuiltiCommand { | ||
async fn execute( | ||
&self, | ||
mut context: crate::context::CommandExecutionContext<'_>, | ||
) -> Result<crate::builtin::BuiltinExitCode, crate::error::Error> { | ||
if let Some(builtin_name) = &self.builtin_name { | ||
if let Some(builtin) = context.shell.builtins.get(builtin_name) { | ||
context.command_name.clone_from(builtin_name); | ||
|
||
let args: Vec<commands::CommandArg> = std::iter::once(builtin_name.into()) | ||
.chain(self.args.iter().map(|arg| arg.into())) | ||
.collect(); | ||
|
||
(builtin.execute_func)(context, args) | ||
.await | ||
.map(|res: crate::builtin::BuiltinResult| res.exit_code) | ||
} else { | ||
writeln!(context.stderr(), "{builtin_name}: command not found")?; | ||
Ok(BuiltinExitCode::Custom(1)) | ||
} | ||
} else { | ||
Ok(BuiltinExitCode::Success) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.