feat: add new shell command "eval"

This commit is contained in:
Demiomad 2025-09-11 17:32:00 +02:00
parent 6d93a1d4f6
commit 1edbd0b6f2
2 changed files with 20 additions and 0 deletions

View 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
}

View file

@ -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;