Skip to content

Commit 5413c35

Browse files
PolishBoiYTuser0-07161
authored andcommitted
feat: add new shell command "eval"
1 parent 6d93a1d commit 5413c35

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

shell/src/ash.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ impl Command for Ash {
3535
path = directory;
3636
env::set_current_dir(&path).unwrap();
3737
}
38+
39+
Action::Nothing => {}
3840
}
3941
} else {
4042
let out = process::Command::new(command)

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)