command_builder : implémentation des builtins
This commit is contained in:
parent
d094decaf9
commit
47b6985816
3 changed files with 14 additions and 5 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use super::builtin::Builtin;
|
||||||
use super::unix_program::UnixProgram;
|
use super::unix_program::UnixProgram;
|
||||||
use super::Command;
|
use super::Command;
|
||||||
|
|
||||||
|
@ -15,8 +16,15 @@ impl CommandBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(&self) -> impl Command {
|
pub fn build(&self) -> Box<dyn Command> {
|
||||||
let command = UnixProgram::new(&self.argv);
|
let builtin = Builtin::new(&self.argv);
|
||||||
|
let command: Box<dyn Command>;
|
||||||
|
|
||||||
|
if builtin.is_err() {
|
||||||
|
command = Box::from(UnixProgram::new(&self.argv));
|
||||||
|
} else {
|
||||||
|
command = Box::from(builtin.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
command
|
command
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,14 @@ pub struct CommandSequence {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommandSequence {
|
impl CommandSequence {
|
||||||
pub fn new(command: impl Command + 'static) -> Self {
|
pub fn new(command: Box<dyn Command>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
command: Box::new(command),
|
command,
|
||||||
next_command: None,
|
next_command: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, command: impl Command + 'static) {
|
pub fn add(&mut self, command: Box<dyn Command>) {
|
||||||
if self.next_command.is_none() {
|
if self.next_command.is_none() {
|
||||||
self.next_command = Some(Box::new(Self::new(command)));
|
self.next_command = Some(Box::new(Self::new(command)));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
pub mod builtin;
|
||||||
pub mod command_builder;
|
pub mod command_builder;
|
||||||
pub mod command_sequence;
|
pub mod command_sequence;
|
||||||
pub mod unix_program;
|
pub mod unix_program;
|
||||||
|
|
Loading…
Reference in a new issue