builtin : organisation du code
This commit is contained in:
parent
bb5598aee7
commit
08b7b57943
1 changed files with 24 additions and 24 deletions
|
@ -6,30 +6,6 @@ use std::{env::set_current_dir, path::PathBuf};
|
|||
|
||||
type BuiltinFunction = fn(&Vec<String>) -> ExitCode;
|
||||
|
||||
pub struct Builtin {
|
||||
function: BuiltinFunction,
|
||||
args: Vec<String>,
|
||||
}
|
||||
|
||||
impl Builtin {
|
||||
pub fn new(argv: &Vec<String>) -> Result<Self, NoSuchBuiltinError> {
|
||||
let mut args = argv.clone();
|
||||
let program = args.remove(0);
|
||||
|
||||
if program == "cd" {
|
||||
Ok(Self { function: cd, args })
|
||||
} else {
|
||||
Err(NoSuchBuiltinError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Command for Builtin {
|
||||
fn spawn(&mut self) -> ExitCode {
|
||||
(self.function)(&self.args)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NoSuchBuiltinError;
|
||||
|
||||
|
@ -61,3 +37,27 @@ fn cd(args: &Vec<String>) -> ExitCode {
|
|||
|
||||
exit_code
|
||||
}
|
||||
|
||||
pub struct Builtin {
|
||||
function: BuiltinFunction,
|
||||
args: Vec<String>,
|
||||
}
|
||||
|
||||
impl Builtin {
|
||||
pub fn new(argv: &Vec<String>) -> Result<Self, NoSuchBuiltinError> {
|
||||
let mut args = argv.clone();
|
||||
let program = args.remove(0);
|
||||
|
||||
if program == "cd" {
|
||||
Ok(Self { function: cd, args })
|
||||
} else {
|
||||
Err(NoSuchBuiltinError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Command for Builtin {
|
||||
fn spawn(&mut self) -> ExitCode {
|
||||
(self.function)(&self.args)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue