use clap::{Parser, Subcommand};
pub mod batch;
pub mod cache;
pub mod completions;
pub mod config;
pub mod explain;
pub mod scan;
pub mod serve;
pub fn run() -> anyhow::Result<u8> {
let cli = Cli::parse();
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?;
runtime.block_on(async move {
match cli.command {
Command::Scan(args) => match scan::execute(args).await {
Ok(code) => Ok(code),
Err(e) => {
let code = scan::exit_code_for(&e);
tracing::error!(error = ?e, exit_code = code, "scan failed");
eprintln!("error: {e:#}");
Ok(code)
},
},
Command::Batch(args) => batch::execute(args).await,
Command::Explain(args) => explain::execute(args).await,
#[cfg(feature = "web")]
Command::Serve(args) => serve::execute(args).await,
Command::Cache(args) => cache::execute(args).await,
Command::Config(args) => config::execute(args).await,
Command::Completions(args) => completions::execute(args),
Command::Version => {
println!(
"repo-trust {} (scoring-model {})",
crate::VERSION,
crate::SCORING_VERSION
);
Ok(0)
},
}
})
}
#[derive(Debug, Parser)]
#[command(
name = "repo-trust",
version = crate::VERSION,
about,
long_about = None,
propagate_version = true,
)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
Scan(scan::ScanArgs),
Batch(batch::BatchArgs),
Explain(explain::ExplainArgs),
#[cfg(feature = "web")]
Serve(serve::ServeArgs),
Cache(cache::CacheArgs),
Config(config::ConfigArgs),
Completions(completions::CompletionsArgs),
Version,
}