Ajout : patterne CommandBuilder

This commit is contained in:
Ahurac 2024-04-11 19:09:19 +02:00
parent bf92de25b6
commit fe54c24916
4 changed files with 7 additions and 7 deletions

View file

@ -16,7 +16,7 @@ impl CommandSequence {
pub fn add(&mut self, command: impl Command + 'static) {
if self.next_command.is_none() {
self.next_command = Some(Box::new(CommandSequence::new(command)));
self.next_command = Some(Box::new(Self::new(command)));
} else {
self.next_command.as_mut().unwrap().add(command);
}

View file

@ -1,3 +1,4 @@
pub mod command_builder;
pub mod command_sequence;
pub mod unix_program;

View file

@ -7,7 +7,8 @@ pub struct UnixProgram {
}
impl UnixProgram {
pub fn new(mut argv: Vec<String>) -> Self {
pub fn new(argv: &Vec<String>) -> Self {
let mut argv = argv.clone();
let program = argv.remove(0);
let mut command = std::process::Command::new(&program);
command.args(argv);

View file

@ -1,14 +1,12 @@
use crate::command::command_builder::CommandBuilder;
use crate::command::command_sequence::CommandSequence;
use crate::command::unix_program::UnixProgram;
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);
let command_sequence = CommandSequence::new(command);
Some(command_sequence)
let command = CommandBuilder::new().argv(argv).build();
Some(CommandSequence::new(command))
} else {
None
}