diff --git a/shell/src/built_in/eval.rs b/shell/src/built_in/eval.rs new file mode 100644 index 0000000..33ea017 --- /dev/null +++ b/shell/src/built_in/eval.rs @@ -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) => { + let _ = output.wait(); + } + Err(err) => println!("{:?}", err) + } + Action::Nothing +} \ No newline at end of file diff --git a/shell/src/built_in/mod.rs b/shell/src/built_in/mod.rs index 37749a6..9b098ce 100644 --- a/shell/src/built_in/mod.rs +++ b/shell/src/built_in/mod.rs @@ -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) -> 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) -> Action> = None;