command : plus lisible
This commit is contained in:
parent
13555cafb3
commit
a05ce8981c
1 changed files with 4 additions and 11 deletions
|
@ -9,9 +9,6 @@ use crate::variables::Variables;
|
||||||
|
|
||||||
type BuiltinFunction = fn(&Vec<String>, &mut Variables, &mut ExitCode);
|
type BuiltinFunction = fn(&Vec<String>, &mut Variables, &mut ExitCode);
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct NoSuchBuiltinError;
|
|
||||||
|
|
||||||
pub trait Command {
|
pub trait Command {
|
||||||
fn spawn(&mut self, variables: &mut Variables, exit_code: &mut ExitCode);
|
fn spawn(&mut self, variables: &mut Variables, exit_code: &mut ExitCode);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +19,7 @@ pub struct Builtin {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 mut args = argv.clone();
|
||||||
let program = args.remove(0);
|
let program = args.remove(0);
|
||||||
|
|
||||||
|
@ -35,13 +32,9 @@ impl Builtin {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
if function.is_some() {
|
match function {
|
||||||
Ok(Self {
|
Some(function) => Ok(Self { function, args }),
|
||||||
function: function.unwrap(),
|
None => Err(()),
|
||||||
args,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Err(NoSuchBuiltinError)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue