diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs index 24aa9b8..ed0a576 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ use rustyline::error::ReadlineError; use rustyline::Editor; -mod builtins; mod parser; mod prompt; @@ -13,7 +12,7 @@ fn main() { let prompt = prompt::Prompt::new().unwrap(); let mut cwd = std::env::current_dir().unwrap(); - let mut status = None; //: std::process::ExitStatus; + let mut status: Option<std::process::ExitStatus> = None; // `()` can be used when no completer is required let mut rl = Editor::<()>::new(); @@ -25,25 +24,13 @@ fn main() { match readline { Ok(line) => { rl.add_history_entry(line.as_str()); - let commands = parser::parse(&line); - match commands[0] { - "!" => println!("{:?}", status), - "cd" => match builtins::cd(&commands[1..], &prompt.home) { - Ok(p) => cwd = p, - Err(e) => eprintln!("Error: {}", e), - }, - "exit" => { - break 'repl; - } - _ => match builtins::run(commands[0], &commands[1..]) { - Ok(s) => { - println!("Ok({})", s); - status = Some(s); - }, - Err(e) => println!("Err({})", e), - }, + + let i = parser::tokenize(&line); + match i.run(&prompt.home, &mut cwd, &status) { + Ok(parser::command::RunResult::Command(s)) => status = Some(s), + Ok(parser::command::RunResult::Builtin) => {} + Err(e) => eprintln!("{}", e), } - //println!("Line: {}", line); } Err(ReadlineError::Interrupted) => { println!("CTRL-C"); @@ -51,11 +38,11 @@ fn main() { } Err(ReadlineError::Eof) => { println!("CTRL-D"); - break; + break 'repl; } Err(err) => { println!("Error: {:?}", err); - break; + break 'repl; } } } |