cli_testing_specialist/cli/
commands.rs1use clap::{Parser, Subcommand, ValueEnum};
2use clap_complete::Shell;
3use std::path::PathBuf;
4
5#[derive(Parser, Debug)]
7#[command(
8 name = "cli-test",
9 version,
10 about = "Comprehensive CLI testing framework",
11 long_about = "Analyzes CLI tools, generates BATS test suites, and produces detailed security reports"
12)]
13pub struct Cli {
14 #[command(subcommand)]
16 pub command: Commands,
17
18 #[arg(short, long, global = true)]
20 pub verbose: bool,
21}
22
23#[derive(Subcommand, Debug)]
25pub enum Commands {
26 #[command(about = "Analyze CLI tool structure and options")]
28 Analyze {
29 #[arg(value_name = "BINARY")]
31 binary: PathBuf,
32
33 #[arg(short, long, default_value = "cli-analysis.json")]
35 output: PathBuf,
36
37 #[arg(short, long, default_value = "3")]
39 depth: u8,
40
41 #[arg(long)]
43 parallel: bool,
44 },
45
46 #[command(about = "Generate BATS test suites from analysis")]
48 Generate {
49 #[arg(value_name = "ANALYSIS")]
51 analysis: PathBuf,
52
53 #[arg(short, long, default_value = "test-output")]
55 output: PathBuf,
56
57 #[arg(short, long, default_value = "all")]
59 categories: String,
60
61 #[arg(long)]
64 include_intensive: bool,
65 },
66
67 #[command(about = "Execute BATS tests and generate reports")]
69 Run {
70 #[arg(value_name = "TEST_DIR")]
72 test_dir: PathBuf,
73
74 #[arg(short, long, default_value = "markdown")]
76 format: ReportFormat,
77
78 #[arg(short, long, default_value = "reports")]
80 output: PathBuf,
81
82 #[arg(short = 't', long, default_value = "300")]
84 timeout: u64,
85
86 #[arg(short = 's', long)]
88 skip: Option<String>,
89 },
90
91 #[command(about = "Validate analysis JSON file structure")]
93 Validate {
94 #[arg(value_name = "FILE")]
96 file: PathBuf,
97 },
98
99 #[command(about = "Generate shell completion scripts")]
101 Completion {
102 #[arg(value_name = "SHELL")]
104 shell: Shell,
105 },
106}
107
108#[derive(ValueEnum, Clone, Debug)]
110pub enum ReportFormat {
111 Markdown,
113
114 Json,
116
117 Html,
119
120 Junit,
122
123 All,
125}
126
127impl ReportFormat {
128 pub fn extension(&self) -> &'static str {
130 match self {
131 Self::Markdown => "md",
132 Self::Json => "json",
133 Self::Html => "html",
134 Self::Junit => "xml",
135 Self::All => "all",
136 }
137 }
138}
139
140#[cfg(test)]
141mod tests {
142 use super::*;
143
144 #[test]
145 fn test_report_format_extension() {
146 assert_eq!(ReportFormat::Markdown.extension(), "md");
147 assert_eq!(ReportFormat::Json.extension(), "json");
148 assert_eq!(ReportFormat::Html.extension(), "html");
149 assert_eq!(ReportFormat::Junit.extension(), "xml");
150 }
151}