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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#![cfg_attr(coverage_nightly, coverage(off))]
// Quality commands (QDD, Enforce) - extracted for file health (CB-040)
use crate::cli::{EnforceOutputFormat, QualityProfile};
use clap::Subcommand;
use std::path::PathBuf;
/// Quality-Driven Development (QDD) subcommands
#[derive(Subcommand)]
#[cfg_attr(test, derive(Debug))]
pub enum QddCommands {
/// Create high-quality code from specification
Create {
/// Type of code to create
#[arg(long, value_enum, default_value = "function")]
code_type: QddCodeType,
/// Name of the code element (function, module, etc.)
#[arg(long)]
name: String,
/// Purpose/description of the code
#[arg(long)]
purpose: String,
/// Quality profile to use
#[arg(long, value_enum, default_value = "standard")]
profile: QddQualityProfile,
/// Input parameters as type:name pairs
#[arg(long, value_parser = parse_parameter)]
input: Vec<(String, String)>,
/// Output type
#[arg(long, default_value = "()")]
output: String,
/// Output file path
#[arg(short, long)]
output_file: Option<PathBuf>,
},
/// Refactor existing code to meet quality standards
Refactor {
/// File to refactor
#[arg(short, long)]
file: PathBuf,
/// Specific function to refactor (optional)
#[arg(long)]
function: Option<String>,
/// Quality profile to target
#[arg(long, value_enum, default_value = "standard")]
profile: QddQualityProfile,
/// Maximum complexity allowed
#[arg(long)]
max_complexity: Option<u32>,
/// Minimum test coverage required (%)
#[arg(long)]
min_coverage: Option<u32>,
/// Output file path (default: overwrite original)
#[arg(short, long)]
output: Option<PathBuf>,
/// Dry run - show what would be changed
#[arg(long)]
dry_run: bool,
},
/// Validate code against quality standards
Validate {
/// File or directory to validate
#[arg(short, long, default_value = ".")]
path: PathBuf,
/// Quality profile to validate against
#[arg(long, value_enum, default_value = "standard")]
profile: QddQualityProfile,
/// Output format
#[arg(long, value_enum, default_value = "summary")]
format: QddOutputFormat,
/// Output file path
#[arg(short, long)]
output: Option<PathBuf>,
/// Fail on any violations
#[arg(long)]
strict: bool,
},
}
/// QDD code types
#[derive(clap::ValueEnum, Clone)]
#[cfg_attr(test, derive(Debug))]
pub enum QddCodeType {
Function,
Module,
Service,
Test,
}
/// QDD quality profiles
#[derive(clap::ValueEnum, Clone, Copy, Debug)]
pub enum QddQualityProfile {
Extreme,
Standard,
Relaxed,
}
/// QDD output formats
#[derive(clap::ValueEnum, Clone)]
#[cfg_attr(test, derive(Debug))]
pub enum QddOutputFormat {
Summary,
Detailed,
Json,
Markdown,
}
/// Parse parameter as type:name
fn parse_parameter(s: &str) -> Result<(String, String), String> {
let parts: Vec<&str> = s.split(':').collect();
if parts.len() != 2 {
return Err("Parameter must be in format type:name".to_string());
}
Ok((parts[0].to_string(), parts[1].to_string()))
}
/// Enforce subcommands
#[derive(Subcommand)]
#[cfg_attr(test, derive(Debug))]
pub enum EnforceCommands {
/// Enforce extreme quality standards
Extreme {
/// Project path to enforce quality on
#[arg(short = 'p', long, default_value = ".")]
project_path: PathBuf,
/// Single file mode - enforce on one file at a time
#[arg(long)]
single_file_mode: bool,
/// Specific file to enforce (implies single file mode)
#[arg(long)]
file: Option<PathBuf>,
/// Dry run - show what would be changed without making changes
#[arg(long)]
dry_run: bool,
/// Quality profile to use
#[arg(long, value_enum, default_value = "extreme")]
profile: QualityProfile,
/// Show progress during enforcement
#[arg(long, default_value_t = true)]
show_progress: bool,
/// Output format
#[arg(short = 'f', long, value_enum, default_value = "summary")]
format: EnforceOutputFormat,
/// Output file path
#[arg(short = 'o', long)]
output: Option<PathBuf>,
/// Maximum iterations before giving up
#[arg(long, default_value_t = 100)]
max_iterations: u32,
/// Target improvement percentage
#[arg(long)]
target_improvement: Option<f32>,
/// Maximum time in seconds
#[arg(long)]
max_time: Option<u64>,
/// Apply suggestions automatically
#[arg(long)]
apply_suggestions: bool,
/// Validate only (no changes)
#[arg(long)]
validate_only: bool,
/// List all violations and exit
#[arg(long)]
list_violations: bool,
/// Configuration file path
#[arg(long)]
config: Option<PathBuf>,
/// CI mode (exit with error on violations)
#[arg(long)]
ci_mode: bool,
/// Include pattern
#[arg(long)]
include: Option<String>,
/// Exclude pattern
#[arg(long)]
exclude: Option<String>,
/// Cache directory
#[arg(long)]
cache_dir: Option<PathBuf>,
/// Clear cache before starting
#[arg(long)]
clear_cache: bool,
},
}
#[cfg(test)]
mod quality_commands_tests {
use super::*;
#[test]
fn test_parse_parameter_valid() {
let (ty, name) = parse_parameter("String:user_id").unwrap();
assert_eq!(ty, "String");
assert_eq!(name, "user_id");
}
#[test]
fn test_parse_parameter_no_colon() {
let err = parse_parameter("no_colon").unwrap_err();
assert!(err.contains("type:name"));
}
#[test]
fn test_parse_parameter_too_many_colons() {
let err = parse_parameter("a:b:c").unwrap_err();
assert!(err.contains("type:name"));
}
#[test]
fn test_parse_parameter_empty_parts() {
let (ty, name) = parse_parameter(":").unwrap();
assert_eq!(ty, "");
assert_eq!(name, "");
}
}