use clap::Parser;
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
mod banner;
mod cli;
mod commands;
mod mcp;
mod update;
mod completion_dynamic;
use cli::Cli;
#[tokio::main]
async fn main() -> std::process::ExitCode {
clap_complete::CompleteEnv::with_factory(|| {
use clap::CommandFactory;
Cli::command()
})
.complete();
let cli = Cli::parse();
let filter = if cli.verbose > 0 {
match cli.verbose {
1 => "rigg=debug",
_ => "rigg=trace,rigg_client=debug",
}
} else if cli.quiet {
"error"
} else {
"rigg=info"
};
tracing_subscriber::registry()
.with(fmt::layer().with_target(false).without_time())
.with(EnvFilter::new(filter))
.init();
if cli.no_color {
colored::control::set_override(false);
}
let is_mcp = matches!(cli.command, cli::Commands::Mcp(_));
let check_update = if cli.quiet || is_mcp || std::env::var_os("RIGG_NO_UPDATE_CHECK").is_some()
{
None
} else {
Some(tokio::spawn(update::check_for_update()))
};
let code = cli.run().await;
if let Some(handle) = check_update {
if let Ok(Some(message)) = handle.await {
eprintln!();
eprintln!("{message}");
}
}
code.into()
}