use clap::Parser;
use roba::cli::{Cli, SubCommand};
use roba::render::Style;
#[tokio::main]
async fn main() {
let cli = Cli::parse();
let plain = cli.ask.plain;
let json = wants_json(&cli);
if let Err(err) = roba::dispatch(cli).await {
let exit_code = roba::classify_exit_code(&err);
if json {
eprintln!("{}", roba::error::render_json(&err, exit_code));
} else {
let style = if plain {
Style::plain()
} else {
Style::detect_for_error()
};
roba::render::print_error(&format!("{err:#}"), &style);
}
std::process::exit(exit_code);
}
}
fn wants_json(cli: &Cli) -> bool {
if cli.ask.json {
return true;
}
match &cli.command {
Some(SubCommand::History(args)) => args.json,
Some(SubCommand::Cost(args)) => args.json,
_ => false,
}
}