Started to implement CmdOutput - keep going...

This commit is contained in:
Justine Pelletreau 2023-03-02 11:46:21 +01:00
parent 4c64bb8038
commit 488c9c6e0a

View File

@ -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<CmdOutput, CmdOutput> {
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..]);