use clap::Parser;
use hrtor::cli::{CLIArgs, FileInfo};
use hrtor::processor::constants::{CommandResult, CommandStatus};
use hrtor::processor::{Hrtor, Processor};
use linefeed::Interface;
pub const PROMPT: &str = "hrtor:> ";
fn main() -> anyhow::Result<()> {
let args: CLIArgs = CLIArgs::parse();
let file: FileInfo = args.read_fileinfo();
let reader = Interface::new(PROMPT)?;
reader.set_prompt(PROMPT.to_string().as_ref())?;
let instance = Hrtor::from(file);
while let CommandStatus::Continue(result) = {
let read = reader.read_line()?;
match instance.processor.handle_command(read) {
Ok(v) => v,
Err(e) => {
eprintln!("{}", e);
CommandStatus::Continue(CommandResult::NothingToDo)
}
}
} {
match result {
CommandResult::Ok => {}
CommandResult::NothingToDo => {}
}
}
println!("Bye!!");
Ok(())
}