feat: add new command
This commit is contained in:
parent
4e552e9e08
commit
ceec79c0fc
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) => {
|
||||||
|
let _ = output.wait();
|
||||||
|
}
|
||||||
|
Err(err) => println!("{:?}", err)
|
||||||
|
}
|
||||||
|
Action::Nothing
|
||||||
|
}
|
||||||
|
|
@ -1,16 +1,19 @@
|
||||||
mod cd;
|
mod cd;
|
||||||
mod exit;
|
mod exit;
|
||||||
|
mod eval;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
Exit,
|
Exit,
|
||||||
ChangeDirectory(String),
|
ChangeDirectory(String),
|
||||||
|
Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_function(command: String) -> Option<fn(Vec<&str>) -> Action> {
|
fn get_function(command: String) -> Option<fn(Vec<&str>) -> Action> {
|
||||||
let registry = [
|
let registry = [
|
||||||
("exit", exit::exit as fn(Vec<&str>) -> Action),
|
("exit", exit::exit as fn(Vec<&str>) -> Action),
|
||||||
("cd", cd::cd 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;
|
let mut function: Option<fn(Vec<&str>) -> Action> = None;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue