use clap::{Parser, Subcommand, ValueEnum};
use fleetreach_core::Severity;
use fleetreach_report as report;
use crate::diff::DiffArgs;
use crate::scan::ScanArgs;
use crate::vex::{VexCheckArgs, VexVerifyArgs};
#[derive(Parser)]
#[command(
name = "fleetreach",
version,
about = "Fleet-native dependency security audit across 12 ecosystems"
)]
pub struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
#[allow(clippy::large_enum_variant)]
enum Commands {
Scan(ScanArgs),
Diff(DiffArgs),
#[command(subcommand)]
Vex(VexCommand),
}
#[derive(Subcommand)]
enum VexCommand {
Check(VexCheckArgs),
Verify(VexVerifyArgs),
}
pub fn dispatch(cli: Cli) -> u8 {
match cli.command {
Commands::Scan(args) => crate::scan::run_scan(args),
Commands::Diff(args) => crate::diff::run_diff(args),
Commands::Vex(VexCommand::Check(args)) => crate::vex::run_vex_check(args),
Commands::Vex(VexCommand::Verify(args)) => crate::vex::run_vex_verify(args),
}
}
pub(crate) fn fail(message: &str) -> u8 {
eprintln!("error: {message}");
2
}
pub(crate) fn usage_fail(message: &str) -> u8 {
eprintln!("error: {message}");
3
}
#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum ReachMode {
Heuristic,
Static,
}
#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum BuildSandbox {
Auto,
Off,
Require,
}
impl From<BuildSandbox> for fleetreach_reach::SandboxPolicy {
fn from(b: BuildSandbox) -> Self {
match b {
BuildSandbox::Auto => fleetreach_reach::SandboxPolicy::Auto,
BuildSandbox::Off => fleetreach_reach::SandboxPolicy::Off,
BuildSandbox::Require => fleetreach_reach::SandboxPolicy::Require,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum Format {
Table,
Json,
Sarif,
Impact,
Blast,
Packages,
PackagesJson,
FixFirst,
Remediation,
RemediationJson,
Vex,
}
#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum VexScopeArg {
Runtime,
Build,
}
impl From<VexScopeArg> for report::VexScope {
fn from(s: VexScopeArg) -> Self {
match s {
VexScopeArg::Runtime => report::VexScope::Runtime,
VexScopeArg::Build => report::VexScope::Build,
}
}
}
#[derive(Clone, Copy, ValueEnum)]
pub(crate) enum SeverityArg {
Low,
Medium,
High,
Critical,
}
impl From<SeverityArg> for Severity {
fn from(s: SeverityArg) -> Self {
match s {
SeverityArg::Low => Severity::Low,
SeverityArg::Medium => Severity::Medium,
SeverityArg::High => Severity::High,
SeverityArg::Critical => Severity::Critical,
}
}
}