#[cfg(feature = "profile")]
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::port::{PortFormat, handle_port};
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),
Port {
#[arg(long, conflicts_with = "json")]
addr: bool,
#[arg(long, conflicts_with = "addr")]
json: bool,
},
#[cfg(feature = "http-server")]
Serve(ServeArgs),
#[cfg(feature = "profile")]
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();
if let Commands::Port { addr, json } = &cli.command {
let format = if *json {
PortFormat::Json
} else if *addr {
PortFormat::Addr
} else {
PortFormat::Port
};
return handle_port(format);
}
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,
#[cfg(feature = "profile")]
Commands::Profile(args) => cli_profile::cmd_profile(config, args).await,
Commands::Port { .. } => unreachable!("port dispatched before async_main"),
}
}