command : plus lisible

This commit is contained in:
Ahurac 2024-04-23 14:04:47 +02:00
parent 13555cafb3
commit a05ce8981c

View file

@ -9,9 +9,6 @@ use crate::variables::Variables;
type BuiltinFunction = fn(&Vec<String>, &mut Variables, &mut ExitCode);
#[derive(Debug)]
pub struct NoSuchBuiltinError;
pub trait Command {
fn spawn(&mut self, variables: &mut Variables, exit_code: &mut ExitCode);
}
@ -22,7 +19,7 @@ pub struct Builtin {
}
impl Builtin {
pub fn new(argv: &Vec<String>) -> Result<Self, NoSuchBuiltinError> {
pub fn new(argv: &Vec<String>) -> Result<Self, ()> {
let mut args = argv.clone();
let program = args.remove(0);
@ -35,13 +32,9 @@ impl Builtin {
_ => None,
};
if function.is_some() {
Ok(Self {
function: function.unwrap(),
args,
})
} else {
Err(NoSuchBuiltinError)
match function {
Some(function) => Ok(Self { function, args }),
None => Err(()),
}
}
}