feature/exit_codes #2

Merged
ahurac merged 2 commits from feature/exit_codes into main 2023-12-11 14:38:58 +01:00
2 changed files with 22 additions and 5 deletions

View file

@ -5,7 +5,7 @@
## To-do ## To-do
- [x] Read commands from `stdin` - [x] Read commands from `stdin`
- [ ] Exit with last child termination code - [x] Exit with last child termination code
- [ ] Handle background jobs - [ ] Handle background jobs
- [ ] Handle pipes - [ ] Handle pipes
- [ ] Handle double quotes - [ ] Handle double quotes

View file

@ -1,4 +1,8 @@
use std::process::exit; use std::io::Result;
use std::process::{
ExitStatus,
exit,
};
mod input; mod input;
mod output; mod output;
@ -9,6 +13,8 @@ fn main() {
let mut buffer = input::Buffer::new(); let mut buffer = input::Buffer::new();
let mut bytes_read: usize = 1; let mut bytes_read: usize = 1;
let mut argv: Option<Vec<String>>; let mut argv: Option<Vec<String>>;
let mut exit_status: Result<ExitStatus>;
let mut exit_code: i32 = 0;
while bytes_read != 0 { while bytes_read != 0 {
output::print_ps1(); output::print_ps1();
@ -16,11 +22,22 @@ fn main() {
argv = buffer.parse(); argv = buffer.parse();
if argv.is_some() { if argv.is_some() {
let _ = job::execute(argv.unwrap()); exit_status = job::execute(argv.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;
}
} else {
exit_code = 1;
}
} }
} }
println!(); println!();
exit(exit_code);
exit(0);
} }