Ajout : patterne CommandBuilder
This commit is contained in:
parent
bf92de25b6
commit
fe54c24916
4 changed files with 7 additions and 7 deletions
|
@ -16,7 +16,7 @@ impl CommandSequence {
|
||||||
|
|
||||||
pub fn add(&mut self, command: impl Command + 'static) {
|
pub fn add(&mut self, command: impl Command + 'static) {
|
||||||
if self.next_command.is_none() {
|
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 {
|
} else {
|
||||||
self.next_command.as_mut().unwrap().add(command);
|
self.next_command.as_mut().unwrap().add(command);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
pub mod command_builder;
|
||||||
pub mod command_sequence;
|
pub mod command_sequence;
|
||||||
pub mod unix_program;
|
pub mod unix_program;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ pub struct UnixProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 program = argv.remove(0);
|
||||||
let mut command = std::process::Command::new(&program);
|
let mut command = std::process::Command::new(&program);
|
||||||
command.args(argv);
|
command.args(argv);
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
|
use crate::command::command_builder::CommandBuilder;
|
||||||
use crate::command::command_sequence::CommandSequence;
|
use crate::command::command_sequence::CommandSequence;
|
||||||
use crate::command::unix_program::UnixProgram;
|
|
||||||
|
|
||||||
pub fn parse_command_line(line: String) -> Option<CommandSequence> {
|
pub fn parse_command_line(line: String) -> Option<CommandSequence> {
|
||||||
let argv: Vec<String> = line.split_whitespace().map(|s| s.to_string()).collect();
|
let argv: Vec<String> = line.split_whitespace().map(|s| s.to_string()).collect();
|
||||||
|
|
||||||
if !argv.is_empty() {
|
if !argv.is_empty() {
|
||||||
let command = UnixProgram::new(argv);
|
let command = CommandBuilder::new().argv(argv).build();
|
||||||
let command_sequence = CommandSequence::new(command);
|
Some(CommandSequence::new(command))
|
||||||
|
|
||||||
Some(command_sequence)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue