use anyhow::Result;
use basil_bin::{Cli, Command, client_cli};
use basil_core::agent_cli;
use clap::Parser;
#[cfg(not(feature = "db-keystore"))]
#[global_allocator]
static GLOBAL_ALLOCATOR: mimalloc::MiMalloc = mimalloc::MiMalloc;
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Command::Init(args) => agent_cli::run_init(cli.socket.as_deref(), &args),
Command::Agent(args) => agent_cli::run_agent(args, basil_bin::VERSION).await,
Command::Bundle(command) => agent_cli::run_bundle(*command),
Command::Explain(args) => {
if args.is_live() {
init_client_tracing();
client_cli::explain_live(cli.socket.as_deref(), &args).await
} else {
agent_cli::run_explain(&args)
}
}
Command::Doctor(args) => agent_cli::run_doctor_command(args).await,
Command::Client(command) => {
init_client_tracing();
client_cli::run(cli.socket, command).await
}
}
}
fn init_client_tracing() {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("warn")),
)
.init();
}