Skip to content

Commit 695b4c4

Browse files
authored
feat(ash): new "eval" command
2 parents 4e552e9 + 1edbd0b commit 695b4c4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

shell/src/built_in/eval.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use crate::built_in::Action;
2+
use std::process::Command;
3+
4+
pub fn eval(arguments: Vec<&str>) -> Action {
5+
if arguments.len() < 1 {
6+
panic!("eval expects **one or more** arguments");
7+
}
8+
9+
let output = Command::new(arguments[0]).args(&arguments[1..]).spawn();
10+
match output {
11+
Ok(mut output) => {
12+
output.wait().expect("failed to wait for process exit");
13+
}
14+
Err(err) => println!("{:?}", err)
15+
}
16+
Action::Nothing
17+
}

shell/src/built_in/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
mod cd;
22
mod exit;
3+
mod eval;
34

45
#[derive(Debug)]
56
pub enum Action {
67
Exit,
78
ChangeDirectory(String),
9+
Nothing
810
}
911

1012
fn get_function(command: String) -> Option<fn(Vec<&str>) -> Action> {
1113
let registry = [
1214
("exit", exit::exit as fn(Vec<&str>) -> Action),
1315
("cd", cd::cd as fn(Vec<&str>) -> Action),
16+
("eval", eval::eval as fn(Vec<&str>) -> Action)
1417
];
1518
let mut function: Option<fn(Vec<&str>) -> Action> = None;
1619

0 commit comments

Comments
 (0)