From 08b7b57943dada7159c8d7a6970aedeac9e0660b Mon Sep 17 00:00:00 2001 From: Ahurac Date: Sun, 14 Apr 2024 15:11:52 +0200 Subject: [PATCH] builtin : organisation du code --- src/command/builtin.rs | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) 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) + } +}