Message d'erreur command not found
This commit is contained in:
parent
d72c587201
commit
546aa13583
3 changed files with 20 additions and 22 deletions
|
@ -2,8 +2,6 @@ use std::io as stdio;
|
|||
use stdio::stdin;
|
||||
use crate::parser;
|
||||
use crate::job;
|
||||
use std::process::ExitStatus;
|
||||
use std::io::Result;
|
||||
|
||||
pub struct Buffer {
|
||||
buffer: String,
|
||||
|
@ -33,12 +31,25 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn try_spawn(&mut self) -> Option<Result<ExitStatus>> {
|
||||
pub fn try_spawn(&mut self) -> Option<i32> {
|
||||
if ! self.buffer.is_empty() {
|
||||
self.argv = parser::parse(&self.buffer);
|
||||
Some(job::execute(&mut self.argv))
|
||||
let result = job::execute(&mut self.argv);
|
||||
|
||||
if result.is_ok() {
|
||||
let result = result.unwrap();
|
||||
|
||||
if result.code().is_some() {
|
||||
return Some(result.code().unwrap());
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
eprintln!("{}", result.unwrap_err());
|
||||
return Some(127);
|
||||
}
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,6 @@ pub fn execute(argv: &mut Vec<String>) -> Result<ExitStatus> {
|
|||
if child.is_ok() {
|
||||
child.unwrap().wait()
|
||||
} else {
|
||||
Err(Error::new(ErrorKind::Other, "failed to spawn child process"))
|
||||
Err(Error::new(ErrorKind::Other, "command not found"))
|
||||
}
|
||||
}
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -3,18 +3,14 @@ mod parser;
|
|||
mod job;
|
||||
mod variables;
|
||||
|
||||
use std::io::Result;
|
||||
use std::process::{
|
||||
ExitStatus,
|
||||
exit,
|
||||
};
|
||||
use std::process::exit;
|
||||
use variables::Variables;
|
||||
use buffer::Buffer;
|
||||
|
||||
fn main() {
|
||||
let mut buffer = Buffer::new();
|
||||
let mut bytes_read: usize = 1;
|
||||
let mut exit_status: Option<Result<ExitStatus>>;
|
||||
let mut exit_status: Option<i32>;
|
||||
let mut exit_code: i32 = 0;
|
||||
let mut variables = Variables::new();
|
||||
|
||||
|
@ -25,16 +21,7 @@ fn main() {
|
|||
exit_status = buffer.try_spawn();
|
||||
|
||||
if exit_status.is_some() {
|
||||
let exit_status = exit_status.unwrap();
|
||||
if exit_status.is_ok() {
|
||||
let exit_status = exit_status.unwrap();
|
||||
|
||||
if exit_status.code().is_some() {
|
||||
exit_code = exit_status.code().unwrap();
|
||||
}
|
||||
} else {
|
||||
exit_code = 1;
|
||||
}
|
||||
exit_code = exit_status.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue