From 3a2e788c3c915c85c1fd26c8f1915a4031debe40 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Wed, 10 Apr 2024 16:43:01 +0200 Subject: [PATCH] =?UTF-8?q?src=20:=20la=20s=C3=A9quence=20de=20commandes?= =?UTF-8?q?=20est=20optionelle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/control.rs | 8 ++++---- src/parser.rs | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/control.rs b/src/control.rs index 74e2a53..3e0f617 100644 --- a/src/control.rs +++ b/src/control.rs @@ -13,14 +13,14 @@ pub fn run() { loop { print_prompt(); - let user_input = get_user_input(); if user_input.is_some() { - let user_input = user_input.unwrap(); - let command_sequence = parse_command_line(user_input); + let command_sequence = parse_command_line(user_input.unwrap()); - current_exit_code = command_sequence.spawn(); + if command_sequence.is_some() { + current_exit_code = command_sequence.unwrap().spawn(); + } } else { println!(); exit(¤t_exit_code); diff --git a/src/parser.rs b/src/parser.rs index c92a80d..dbdead1 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,11 +1,14 @@ use crate::command::{CommandSequence, UnixProgram}; -pub fn parse_command_line(line: String) -> CommandSequence { - let /*mut*/ command_sequence = CommandSequence::new(); +pub fn parse_command_line(line: String) -> Option { + let argv: Vec = line.split_whitespace().map(|s| s.to_string()).collect(); - let argv = line.split_whitespace().map(|s| s.to_string()).collect(); - let _command = UnixProgram::new().argv(argv); - // command_sequence.add(command); - - command_sequence + if !argv.is_empty() { + let _command = UnixProgram::new().argv(argv); + let command_sequence = CommandSequence::new(); + // command_sequence.add(_command); + Some(command_sequence) + } else { + None + } }