From dc0e63b8e6e69b31139c5cd0b5b5011f67044d5a Mon Sep 17 00:00:00 2001 From: Ahurac Date: Wed, 10 Apr 2024 12:31:57 +0200 Subject: [PATCH] command : ajout `struct` `CommandSequence` --- src/command.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/command.rs b/src/command.rs index 4170a4e..64112cd 100644 --- a/src/command.rs +++ b/src/command.rs @@ -18,6 +18,45 @@ pub trait Command { fn spawn(&self) -> ExitCode; } +pub struct CommandSequence { + command: Option>, + next_command: Option>, +} + +impl CommandSequence { + pub fn new() -> Self { + Self { + command: None, + next_command: None, + } + } + + /* + pub fn add(&self, command: &dyn Command) { + if self.command.is_none() { + let my_box = Box::new(command.to_owned()); + self.command = Some(my_box); + } + } + */ +} + +impl Command for CommandSequence { + fn spawn(&self) -> ExitCode { + let mut exit_code = ExitCode::new(0); + + if self.command.is_some() { + exit_code = self.command.as_ref().unwrap().spawn(); + } + + if self.next_command.is_some() { + exit_code = self.next_command.as_ref().unwrap().spawn(); + } + + exit_code + } +} + pub struct UnixProgram { argv: Vec, }