From 47b698581665bb11e04df026f3597eea1423e35d Mon Sep 17 00:00:00 2001 From: Ahurac Date: Thu, 11 Apr 2024 21:34:04 +0200 Subject: [PATCH] =?UTF-8?q?command=5Fbuilder=20:=20impl=C3=A9mentation=20d?= =?UTF-8?q?es=20builtins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/command/command_builder.rs | 12 ++++++++++-- src/command/command_sequence.rs | 6 +++--- src/command/mod.rs | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/command/command_builder.rs b/src/command/command_builder.rs index b7e88be..6b409bb 100644 --- a/src/command/command_builder.rs +++ b/src/command/command_builder.rs @@ -1,3 +1,4 @@ +use super::builtin::Builtin; use super::unix_program::UnixProgram; use super::Command; @@ -15,8 +16,15 @@ impl CommandBuilder { self } - pub fn build(&self) -> impl Command { - let command = UnixProgram::new(&self.argv); + pub fn build(&self) -> Box { + let builtin = Builtin::new(&self.argv); + let command: Box; + + if builtin.is_err() { + command = Box::from(UnixProgram::new(&self.argv)); + } else { + command = Box::from(builtin.unwrap()); + } command } diff --git a/src/command/command_sequence.rs b/src/command/command_sequence.rs index 443d7c9..df61e36 100644 --- a/src/command/command_sequence.rs +++ b/src/command/command_sequence.rs @@ -7,14 +7,14 @@ pub struct CommandSequence { } impl CommandSequence { - pub fn new(command: impl Command + 'static) -> Self { + pub fn new(command: Box) -> Self { Self { - command: Box::new(command), + command, next_command: None, } } - pub fn add(&mut self, command: impl Command + 'static) { + pub fn add(&mut self, command: Box) { if self.next_command.is_none() { self.next_command = Some(Box::new(Self::new(command))); } else { diff --git a/src/command/mod.rs b/src/command/mod.rs index c369d2a..da38895 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -1,3 +1,4 @@ +pub mod builtin; pub mod command_builder; pub mod command_sequence; pub mod unix_program;