diff --git a/src/lib.rs b/src/lib.rs index babd18c..92c4fb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,15 +69,34 @@ pub mod shell { } } - fn process_line(input: &str) -> String { + struct CmdOutput { + outp: String, + rc: i16, + } + + impl CmdOutput { + fn from_values(output: String, rc: i16) -> CmdOutput { + let myoutp = CmdOutput { + outp: output, + rc: rc, + } + return myoutp; + } + } + + fn process_line(input: &str) -> Result { let mut commands = input.trim().split("|").peekable(); let mut previous_command = None; let mut resultat = String::new(); + let mut outp = CmdOutput::new_empty(); + while let Some(command) = commands.next() { let parts = match shell_words::split(&command.trim()) { Ok(w) => w, - Err(e) => { return format!("Error parsing the command : {:?}", e); }, + Err(e) => { + return Err(CmdOutput::from_values(format!("Could not parse command {:?}", e), -1)); + }, }; let command = parts[0].as_str(); let args = Vec::from(&parts[1..]);