src : la première commande de CommandSequence n'est plus optionnelle

This commit is contained in:
Ahurac 2024-04-11 01:15:20 +02:00
parent 3a2e788c3c
commit 7ffbc9a608
2 changed files with 8 additions and 17 deletions

View file

@ -23,14 +23,14 @@ pub trait Command {
}
pub struct CommandSequence {
command: Option<Box<dyn Command>>,
command: Box<dyn Command>,
next_command: Option<Box<dyn Command>>,
}
impl CommandSequence {
pub fn new() -> Self {
pub fn new(command: impl Command + 'static) -> Self {
Self {
command: None,
command: Box::new(command),
next_command: None,
}
}
@ -47,11 +47,7 @@ impl CommandSequence {
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();
}
let mut exit_code = self.command.spawn();
if self.next_command.is_some() {
exit_code = self.next_command.as_ref().unwrap().spawn();
@ -66,13 +62,8 @@ pub struct UnixProgram {
}
impl UnixProgram {
pub fn new() -> Self {
Self { argv: Vec::new() }
}
pub fn argv(&mut self, argv: Vec<String>) -> &mut Self {
self.argv = argv;
self
pub fn new(argv: Vec<String>) -> Self {
Self { argv }
}
}

View file

@ -4,8 +4,8 @@ pub fn parse_command_line(line: String) -> Option<CommandSequence> {
let argv: Vec<String> = line.split_whitespace().map(|s| s.to_string()).collect();
if !argv.is_empty() {
let _command = UnixProgram::new().argv(argv);
let command_sequence = CommandSequence::new();
let command = UnixProgram::new(argv);
let command_sequence = CommandSequence::new(command);
// command_sequence.add(_command);
Some(command_sequence)
} else {