feat: add new shell command "eval"
This commit is contained in:
parent
6d93a1d4f6
commit
1edbd0b6f2
2 changed files with 20 additions and 0 deletions
17
shell/src/built_in/eval.rs
Normal file
17
shell/src/built_in/eval.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use crate::built_in::Action;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn eval(arguments: Vec<&str>) -> Action {
|
||||
if arguments.len() < 1 {
|
||||
panic!("eval expects **one or more** arguments");
|
||||
}
|
||||
|
||||
let output = Command::new(arguments[0]).args(&arguments[1..]).spawn();
|
||||
match output {
|
||||
Ok(mut output) => {
|
||||
output.wait().expect("failed to wait for process exit");
|
||||
}
|
||||
Err(err) => println!("{:?}", err)
|
||||
}
|
||||
Action::Nothing
|
||||
}
|
||||
|
|
@ -1,16 +1,19 @@
|
|||
mod cd;
|
||||
mod exit;
|
||||
mod eval;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Action {
|
||||
Exit,
|
||||
ChangeDirectory(String),
|
||||
Nothing
|
||||
}
|
||||
|
||||
fn get_function(command: String) -> Option<fn(Vec<&str>) -> Action> {
|
||||
let registry = [
|
||||
("exit", exit::exit as fn(Vec<&str>) -> Action),
|
||||
("cd", cd::cd as fn(Vec<&str>) -> Action),
|
||||
("eval", eval::eval as fn(Vec<&str>) -> Action)
|
||||
];
|
||||
let mut function: Option<fn(Vec<&str>) -> Action> = None;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue