1use clap::{Parser, Subcommand, ValueEnum};
2use std::path::PathBuf;
3
4#[derive(Parser)]
5#[command(name = "sync-ctl")]
6#[command(version = env!("CARGO_PKG_VERSION"))]
7#[command(about = "Generate Infrastructure as Code from your codebase")]
8#[command(long_about = "A powerful CLI tool that analyzes your codebase and automatically generates optimized Infrastructure as Code configurations including Dockerfiles, Docker Compose files, and Terraform configurations.")]
9pub struct Cli {
10 #[command(subcommand)]
11 pub command: Commands,
12
13 #[arg(short, long, global = true, value_name = "FILE")]
15 pub config: Option<PathBuf>,
16
17 #[arg(short, long, global = true, action = clap::ArgAction::Count)]
19 pub verbose: u8,
20
21 #[arg(short, long, global = true)]
23 pub quiet: bool,
24
25 #[arg(long, global = true)]
27 pub json: bool,
28
29 #[arg(long, global = true)]
31 pub clear_update_cache: bool,
32}
33
34#[derive(Subcommand)]
35pub enum Commands {
36 Analyze {
38 #[arg(value_name = "PROJECT_PATH")]
40 path: PathBuf,
41
42 #[arg(short, long)]
44 json: bool,
45
46 #[arg(short, long, conflicts_with = "display")]
48 detailed: bool,
49
50 #[arg(long, value_enum, default_value = "matrix")]
52 display: Option<DisplayFormat>,
53
54 #[arg(long, value_delimiter = ',')]
56 only: Option<Vec<String>>,
57 },
58
59 Generate {
61 #[arg(value_name = "PROJECT_PATH")]
63 path: PathBuf,
64
65 #[arg(short, long, value_name = "OUTPUT_DIR")]
67 output: Option<PathBuf>,
68
69 #[arg(long)]
71 dockerfile: bool,
72
73 #[arg(long)]
75 compose: bool,
76
77 #[arg(long)]
79 terraform: bool,
80
81 #[arg(long, conflicts_with_all = ["dockerfile", "compose", "terraform"])]
83 all: bool,
84
85 #[arg(long)]
87 dry_run: bool,
88
89 #[arg(long)]
91 force: bool,
92 },
93
94 Validate {
96 #[arg(value_name = "PATH")]
98 path: PathBuf,
99
100 #[arg(long, value_delimiter = ',')]
102 types: Option<Vec<String>>,
103
104 #[arg(long)]
106 fix: bool,
107 },
108
109 Support {
111 #[arg(long)]
113 languages: bool,
114
115 #[arg(long)]
117 frameworks: bool,
118
119 #[arg(short, long)]
121 detailed: bool,
122 },
123
124 Dependencies {
126 #[arg(value_name = "PROJECT_PATH")]
128 path: PathBuf,
129
130 #[arg(long)]
132 licenses: bool,
133
134 #[arg(long)]
136 vulnerabilities: bool,
137
138 #[arg(long, conflicts_with = "dev_only")]
140 prod_only: bool,
141
142 #[arg(long, conflicts_with = "prod_only")]
144 dev_only: bool,
145
146 #[arg(long, value_enum, default_value = "table")]
148 format: OutputFormat,
149 },
150
151 Vulnerabilities {
153 #[arg(default_value = ".")]
155 path: PathBuf,
156
157 #[arg(long, value_enum)]
159 severity: Option<SeverityThreshold>,
160
161 #[arg(long, value_enum, default_value = "table")]
163 format: OutputFormat,
164
165 #[arg(long)]
167 output: Option<PathBuf>,
168 },
169
170 Security {
172 #[arg(value_name = "PROJECT_PATH", default_value = ".")]
174 path: PathBuf,
175
176 #[arg(long)]
178 include_low: bool,
179
180 #[arg(long)]
182 no_secrets: bool,
183
184 #[arg(long)]
186 no_code_patterns: bool,
187
188 #[arg(long, hide = true)]
190 no_infrastructure: bool,
191
192 #[arg(long, hide = true)]
194 no_compliance: bool,
195
196 #[arg(long, value_delimiter = ',', hide = true)]
198 frameworks: Vec<String>,
199
200 #[arg(long, value_enum, default_value = "table")]
202 format: OutputFormat,
203
204 #[arg(long)]
206 output: Option<PathBuf>,
207
208 #[arg(long)]
210 fail_on_findings: bool,
211 },
212
213 Tools {
215 #[command(subcommand)]
216 command: ToolsCommand,
217 },
218}
219
220#[derive(Subcommand)]
221pub enum ToolsCommand {
222 Status {
224 #[arg(long, value_enum, default_value = "table")]
226 format: OutputFormat,
227
228 #[arg(long, value_delimiter = ',')]
230 languages: Option<Vec<String>>,
231 },
232
233 Install {
235 #[arg(long, value_delimiter = ',')]
237 languages: Option<Vec<String>>,
238
239 #[arg(long)]
241 include_owasp: bool,
242
243 #[arg(long)]
245 dry_run: bool,
246
247 #[arg(short, long)]
249 yes: bool,
250 },
251
252 Verify {
254 #[arg(long, value_delimiter = ',')]
256 languages: Option<Vec<String>>,
257
258 #[arg(short, long)]
260 verbose: bool,
261 },
262
263 Guide {
265 #[arg(long, value_delimiter = ',')]
267 languages: Option<Vec<String>>,
268
269 #[arg(long)]
271 platform: Option<String>,
272 },
273}
274
275#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
276pub enum OutputFormat {
277 Table,
278 Json,
279}
280
281#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
282pub enum DisplayFormat {
283 Matrix,
285 Detailed,
287 Summary,
289}
290
291#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
292pub enum SeverityThreshold {
293 Low,
294 Medium,
295 High,
296 Critical,
297}
298
299impl Cli {
300 pub fn init_logging(&self) {
302 if self.quiet {
303 return;
304 }
305
306 let level = match self.verbose {
307 0 => log::LevelFilter::Warn,
308 1 => log::LevelFilter::Info,
309 2 => log::LevelFilter::Debug,
310 _ => log::LevelFilter::Trace,
311 };
312
313 env_logger::Builder::from_default_env()
314 .filter_level(level)
315 .init();
316 }
317}