1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
use clap::{Parser, Subcommand, ValueEnum};
use repopilot::baseline::gate::FailOn;
use repopilot::findings::types::Severity;
use repopilot::output::OutputFormat;
use std::path::PathBuf;
#[derive(Parser)]
#[command(name = "repopilot")]
#[command(version)]
#[command(
about = "Local-first CLI for repository audit, architecture risk detection, baseline tracking, and CI-friendly code review.",
long_about = None
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
/// Manage accepted baseline findings
Baseline {
#[command(subcommand)]
command: BaselineCommands,
},
/// Compare two JSON scan reports and show what changed
Compare {
/// Path to the earlier scan report (JSON)
before: std::path::PathBuf,
/// Path to the more recent scan report (JSON)
after: std::path::PathBuf,
/// Output format
#[arg(long, value_enum, default_value = "console")]
format: CompareOutputFormatArg,
/// Write report to a file instead of stdout
#[arg(short, long)]
output: Option<std::path::PathBuf>,
},
/// Scan a project, folder, or file
Scan {
/// Path to project, folder, or file
path: PathBuf,
/// Output format
#[arg(long, value_enum)]
format: Option<OutputFormatArg>,
/// Write report to a file instead of stdout
#[arg(short, long)]
output: Option<PathBuf>,
/// Path to a RepoPilot config file
#[arg(long)]
config: Option<PathBuf>,
/// Path to a RepoPilot baseline file
#[arg(long)]
baseline: Option<PathBuf>,
/// Fail with exit code 1 when findings meet the selected threshold
#[arg(long, value_enum)]
fail_on: Option<FailOnArg>,
/// Maximum non-empty LOC before a file is reported as large (default: 300)
#[arg(long)]
max_file_loc: Option<usize>,
/// Maximum number of files in a single directory before flagging (default: 20)
#[arg(long)]
max_directory_modules: Option<usize>,
/// Maximum directory nesting depth before flagging (default: 5)
#[arg(long)]
max_directory_depth: Option<usize>,
},
/// Review findings that touch changed Git diff lines
Review {
/// Path to project, folder, or file
#[arg(default_value = ".")]
path: PathBuf,
/// Base Git ref for review diff. Without this, review compares the working tree against HEAD
#[arg(long)]
base: Option<String>,
/// Head Git ref for review diff. Requires --base and defaults to HEAD when --base is set
#[arg(long)]
head: Option<String>,
/// Path to a RepoPilot config file
#[arg(long)]
config: Option<PathBuf>,
/// Path to a RepoPilot baseline file
#[arg(long)]
baseline: Option<PathBuf>,
/// Fail with exit code 1 when in-diff findings meet the selected threshold
#[arg(long, value_enum)]
fail_on: Option<FailOnArg>,
/// Output format
#[arg(long, value_enum, default_value = "console")]
format: CompareOutputFormatArg,
/// Write report to a file instead of stdout
#[arg(short, long)]
output: Option<PathBuf>,
/// Maximum non-empty LOC before a file is reported as large (default: 300)
#[arg(long)]
max_file_loc: Option<usize>,
/// Maximum number of files in a single directory before flagging (default: 20)
#[arg(long)]
max_directory_modules: Option<usize>,
/// Maximum directory nesting depth before flagging (default: 5)
#[arg(long)]
max_directory_depth: Option<usize>,
},
/// Generate a default repopilot.toml configuration file
Init {
/// Overwrite an existing config file
#[arg(long)]
force: bool,
/// Path where the config file should be written
#[arg(long, default_value = "repopilot.toml")]
path: PathBuf,
},
}
#[derive(Subcommand)]
pub enum BaselineCommands {
/// Scan a path and store the current findings as accepted debt
Create {
/// Path to project, folder, or file
path: PathBuf,
/// Write baseline to a custom path
#[arg(short, long)]
output: Option<PathBuf>,
/// Overwrite an existing baseline file
#[arg(long)]
force: bool,
},
}
#[derive(Clone, Copy, Debug, ValueEnum)]
pub enum OutputFormatArg {
Console,
Html,
Json,
Markdown,
}
#[derive(Clone, Copy, Debug, ValueEnum)]
pub enum CompareOutputFormatArg {
Console,
Json,
Markdown,
}
#[derive(Clone, Copy, Debug, ValueEnum)]
pub enum FailOnArg {
NewLow,
NewMedium,
NewHigh,
NewCritical,
Low,
Medium,
High,
Critical,
}
impl From<OutputFormatArg> for OutputFormat {
fn from(format: OutputFormatArg) -> Self {
match format {
OutputFormatArg::Console => OutputFormat::Console,
OutputFormatArg::Html => OutputFormat::Html,
OutputFormatArg::Json => OutputFormat::Json,
OutputFormatArg::Markdown => OutputFormat::Markdown,
}
}
}
impl From<FailOnArg> for FailOn {
fn from(value: FailOnArg) -> Self {
match value {
FailOnArg::NewLow => FailOn::New(Severity::Low),
FailOnArg::NewMedium => FailOn::New(Severity::Medium),
FailOnArg::NewHigh => FailOn::New(Severity::High),
FailOnArg::NewCritical => FailOn::New(Severity::Critical),
FailOnArg::Low => FailOn::Any(Severity::Low),
FailOnArg::Medium => FailOn::Any(Severity::Medium),
FailOnArg::High => FailOn::Any(Severity::High),
FailOnArg::Critical => FailOn::Any(Severity::Critical),
}
}
}