use anyhow::Result;
use clap::{CommandFactory, Parser};
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
mod banner;
mod cli;
mod commands;
mod output;
mod update;
use cli::Cli;
#[tokio::main]
async fn main() -> Result<()> {
clap_complete::CompleteEnv::with_factory(Cli::command).complete();
let cli = Cli::parse();
let filter = if cli.verbose > 0 {
match cli.verbose {
1 => "cosq=debug",
_ => "cosq=trace",
}
} else if cli.quiet {
"error"
} else {
"cosq=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 update_handle = if !cli.quiet && std::env::var("COSQ_NO_UPDATE_CHECK").is_err() {
Some(tokio::spawn(update::check_for_updates()))
} else {
None
};
let result = cli.run().await;
if let Some(handle) = update_handle {
let _ = handle.await;
}
result
}