Add status variable
This commit is contained in:
parent
43e82b822b
commit
746790f91b
15
src/main.rs
15
src/main.rs
|
@ -4,6 +4,9 @@ use std::process::Command;
|
|||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
// Variables
|
||||
let mut STATUS = 0;
|
||||
|
||||
loop {
|
||||
print!("$ ");
|
||||
io::stdout().flush();
|
||||
|
@ -16,8 +19,16 @@ fn main() {
|
|||
let args = parts;
|
||||
|
||||
match command {
|
||||
"true" | ":" => {
|
||||
STATUS = 0;
|
||||
},
|
||||
"echo" => {
|
||||
println!("{}", args.peekable().peek().map_or("/", |x| *x));
|
||||
let args = args.peekable().peek().map_or("/", |x| *x);
|
||||
if args.clone() == "$STATUS" {
|
||||
println!("{}", STATUS);
|
||||
} else {
|
||||
println!("{}", args);
|
||||
}
|
||||
},
|
||||
"cd" => {
|
||||
let new_dir = args.peekable().peek().map_or("/", |x| *x);
|
||||
|
@ -34,7 +45,7 @@ fn main() {
|
|||
|
||||
match child {
|
||||
Ok(mut child) => { child.wait(); },
|
||||
Err(e) => eprintln!("{}", e),
|
||||
Err(e) => { STATUS=1; eprintln!("{}", e); },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue