osdb/src/main.rs

41 lines
1.1 KiB
Rust

use osdb::branding::startup_msg;
use osdb::cli::{history_file, read_input};
use osdb::error_display::OSDBError as _;
use osdb::parser::parse;
fn main() {
let mut rl = rustyline::DefaultEditor::new().expect("failed to create stdin reader");
let history_file = history_file();
if let Some(history_file) = &history_file {
let _ = rl.load_history(history_file);
}
println!("{}", startup_msg());
'main: while let Some(input) = read_input(&mut rl) {
let file = String::from("<stdin>");
match parse(file.clone(), input.clone()) {
Ok(cmds) => {
for cmd in cmds {
let result = cmd.execute();
if result.should_exit {
break 'main;
}
println!("{}", result.display());
}
}
Err(errs) => {
for err in errs {
err.display(&file, &input)
}
}
}
}
if let Some(history_file) = &history_file {
let _ = rl.save_history(history_file);
}
println!("Good-bye");
}