diff --git a/src/command/command_sequence.rs b/src/command/command_sequence.rs index 4918d76..4ac32a7 100644 --- a/src/command/command_sequence.rs +++ b/src/command/command_sequence.rs @@ -27,6 +27,10 @@ impl CommandSequence { self.next_command.as_mut().unwrap().add(command); } } + + pub fn is_empty(&self) -> bool { + self.command.is_none() + } } impl Command for CommandSequence { diff --git a/src/control.rs b/src/control.rs index 5695a78..585a295 100644 --- a/src/control.rs +++ b/src/control.rs @@ -17,10 +17,10 @@ pub fn run() { let user_input = get_user_input(); if user_input.is_some() { - let command_sequence = parse(user_input.unwrap()); + let mut command_sequence = parse(user_input.unwrap()); - if command_sequence.is_some() { - current_exit_code = command_sequence.unwrap().spawn(); + if !command_sequence.is_empty() { + current_exit_code = command_sequence.spawn(); } } else { println!(); diff --git a/src/parser.rs b/src/parser.rs index cb9207e..e96621d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -37,6 +37,8 @@ fn parse_main(characters: &mut Vec, current_arg: &mut String) -> Vec, current_arg: &mut String) -> Vec Option { +pub fn parse(line: String) -> CommandSequence { let mut characters: Vec = line.chars().rev().collect(); + let mut command_sequence = CommandSequence::new(); - None - /* - let argv = parse_main(&mut characters, &mut String::default()); + while !characters.is_empty() { + let argv = parse_main(&mut characters, &mut String::default()); - if !argv.is_empty() { - let command = CommandBuilder::new(argv).build(); - let mut command_sequence = CommandSequence::new(); - command_sequence.add(command); - Some(command_sequence) - } else { - None + if !argv.is_empty() { + let command = CommandBuilder::new(argv).build(); + command_sequence.add(command); + } } - */ + + command_sequence } #[derive(Debug)]