1use clap::{Parser, Subcommand, ValueEnum};
7use fleetreach_core::Severity;
8use fleetreach_report as report;
9
10use crate::diff::DiffArgs;
11use crate::scan::ScanArgs;
12use crate::vex::{VexCheckArgs, VexVerifyArgs};
13
14#[derive(Parser)]
15#[command(
16 name = "fleetreach",
17 version,
18 about = "Fleet-native dependency security audit across 12 ecosystems"
19)]
20pub struct Cli {
21 #[command(subcommand)]
22 command: Commands,
23}
24
25#[derive(Subcommand)]
26#[allow(clippy::large_enum_variant)]
29enum Commands {
30 Scan(ScanArgs),
32 Diff(DiffArgs),
34 #[command(subcommand)]
36 Vex(VexCommand),
37}
38
39#[derive(Subcommand)]
40enum VexCommand {
41 Check(VexCheckArgs),
43 Verify(VexVerifyArgs),
45}
46
47pub fn dispatch(cli: Cli) -> u8 {
49 match cli.command {
50 Commands::Scan(args) => crate::scan::run_scan(args),
51 Commands::Diff(args) => crate::diff::run_diff(args),
52 Commands::Vex(VexCommand::Check(args)) => crate::vex::run_vex_check(args),
53 Commands::Vex(VexCommand::Verify(args)) => crate::vex::run_vex_verify(args),
54 }
55}
56
57pub(crate) fn fail(message: &str) -> u8 {
59 eprintln!("error: {message}");
60 2
61}
62
63pub(crate) fn usage_fail(message: &str) -> u8 {
66 eprintln!("error: {message}");
67 3
68}
69
70#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
71pub(crate) enum ReachMode {
72 Heuristic,
74 Static,
76}
77
78#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
79pub(crate) enum BuildSandbox {
80 Auto,
82 Off,
84 Require,
86}
87
88impl From<BuildSandbox> for fleetreach_reach::SandboxPolicy {
89 fn from(b: BuildSandbox) -> Self {
90 match b {
91 BuildSandbox::Auto => fleetreach_reach::SandboxPolicy::Auto,
92 BuildSandbox::Off => fleetreach_reach::SandboxPolicy::Off,
93 BuildSandbox::Require => fleetreach_reach::SandboxPolicy::Require,
94 }
95 }
96}
97
98#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
99pub(crate) enum Format {
100 Table,
101 Json,
102 Sarif,
104 Impact,
106 Blast,
109 Packages,
112 PackagesJson,
114 FixFirst,
117 Remediation,
120 RemediationJson,
122 Vex,
124}
125
126#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
127pub(crate) enum VexScopeArg {
128 Runtime,
129 Build,
130}
131
132impl From<VexScopeArg> for report::VexScope {
133 fn from(s: VexScopeArg) -> Self {
134 match s {
135 VexScopeArg::Runtime => report::VexScope::Runtime,
136 VexScopeArg::Build => report::VexScope::Build,
137 }
138 }
139}
140
141#[derive(Clone, Copy, ValueEnum)]
142pub(crate) enum SeverityArg {
143 Low,
144 Medium,
145 High,
146 Critical,
147}
148
149impl From<SeverityArg> for Severity {
150 fn from(s: SeverityArg) -> Self {
151 match s {
152 SeverityArg::Low => Severity::Low,
153 SeverityArg::Medium => Severity::Medium,
154 SeverityArg::High => Severity::High,
155 SeverityArg::Critical => Severity::Critical,
156 }
157 }
158}