diff --git a/src/command/builtin.rs b/src/command/builtin.rs index 5abc0d3..d0d3db3 100644 --- a/src/command/builtin.rs +++ b/src/command/builtin.rs @@ -6,30 +6,6 @@ use std::{env::set_current_dir, path::PathBuf}; type BuiltinFunction = fn(&Vec) -> ExitCode; -pub struct Builtin { - function: BuiltinFunction, - args: Vec, -} - -impl Builtin { - pub fn new(argv: &Vec) -> Result { - 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) -> ExitCode { exit_code } + +pub struct Builtin { + function: BuiltinFunction, + args: Vec, +} + +impl Builtin { + pub fn new(argv: &Vec) -> Result { + 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) + } +}