mod cli_profile;
mod cli_verify;
mod commands;
use anyhow::{Context as _, Result};
use clap::{Parser, Subcommand};
use trusty_review::config::ReviewConfig;
use commands::compare::{CompareArgs, cmd_compare};
use commands::run::{RunArgs, cmd_run};
#[cfg(feature = "http-server")]
use commands::serve::{ServeArgs, cmd_serve};
#[derive(Debug, Parser)]
#[command(
name = "trusty-review",
version = env!("CARGO_PKG_VERSION"),
about = "Fast local PR-review service — LLM-backed code review",
long_about = None,
)]
struct Cli {
#[arg(long, global = true, value_name = "PATH")]
config: Option<std::path::PathBuf>,
#[command(subcommand)]
command: Commands,
}
#[derive(Debug, Subcommand)]
enum Commands {
Run(RunArgs),
Compare(CompareArgs),
#[cfg(feature = "http-server")]
Serve(ServeArgs),
Profile(cli_profile::ProfileArgs),
}
fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("warn")),
)
.init();
let cli = Cli::parse();
let rt = tokio::runtime::Runtime::new().context("build tokio runtime")?;
rt.block_on(async_main(cli))
}
async fn async_main(cli: Cli) -> Result<()> {
let config = ReviewConfig::from_env_and_file(cli.config.as_deref(), None);
match cli.command {
Commands::Run(args) => cmd_run(config, args).await,
Commands::Compare(args) => cmd_compare(config, args).await,
#[cfg(feature = "http-server")]
Commands::Serve(args) => cmd_serve(config, args).await,
Commands::Profile(args) => cli_profile::cmd_profile(config, args).await,
}
}