1pub mod commands;
7pub mod types;
8pub mod utils;
9
10use crate::error::Result;
11use clap::Parser;
12use std::path::PathBuf;
13use tracing::error;
14
15pub async fn run_cli() -> Result<()> {
19 let cli = Cli::parse();
20
21 setup_logging(cli.verbose)?;
23
24 let result = match cli.command {
25 Commands::Run {
26 paths,
27 parallel,
28 jobs,
29 fail_fast,
30 watch,
31 interactive,
32 } => {
33 let config = crate::cli::types::CliConfig {
34 parallel,
35 jobs,
36 format: cli.format.clone(),
37 fail_fast,
38 watch,
39 interactive,
40 verbose: cli.verbose,
41 };
42
43 let paths_to_run = if let Some(paths) = paths {
45 paths
46 } else {
47 vec![PathBuf::from(".")]
49 };
50
51 run_tests(&paths_to_run, &config).await
52 }
53
54 Commands::Validate { files } => {
55 for file in files {
56 validate_config(&file)?;
57 }
58 Ok(())
59 }
60
61 Commands::Init { force, config } => {
62 init_project(force, config)?;
63 Ok(())
64 }
65
66 Commands::Template { template, name } => {
67 generate_from_template(&template, name.as_deref())?;
68 Ok(())
69 }
70
71 Commands::Plugins => {
72 list_plugins()?;
73 Ok(())
74 }
75
76 Commands::Services { command } => match command {
77 ServiceCommands::Status => {
78 show_service_status().await?;
79 Ok(())
80 }
81 ServiceCommands::Logs { service, lines } => {
82 show_service_logs(&service, lines).await?;
83 Ok(())
84 }
85 ServiceCommands::Restart { service } => {
86 restart_service(&service).await?;
87 Ok(())
88 }
89 ServiceCommands::AiManage {
90 auto_scale: _,
91 predict_load: _,
92 optimize_resources: _,
93 horizon_minutes: _,
94 service: _,
95 } => {
96 Err(crate::error::CleanroomError::validation_error(
97 "AI service management is an experimental feature in the clnrm-ai crate.\n\
98 To use this feature, enable the 'ai' feature flag or use the clnrm-ai crate directly."
99 ))
100 }
101 },
102
103 Commands::Report {
104 input,
105 output,
106 format,
107 } => {
108 let format_str = match format {
109 ReportFormat::Html => "html",
110 ReportFormat::Markdown => "markdown",
111 ReportFormat::Json => "json",
112 ReportFormat::Pdf => "pdf",
113 };
114 generate_report(input.as_ref(), output.as_ref(), format_str).await?;
115 Ok(())
116 }
117
118 Commands::SelfTest { suite, report } => {
119 run_self_tests(suite, report).await?;
120 Ok(())
121 }
122
123 Commands::AiOrchestrate {
124 paths: _,
125 predict_failures: _,
126 auto_optimize: _,
127 confidence_threshold: _,
128 max_workers: _,
129 } => {
130 Err(crate::error::CleanroomError::validation_error(
131 "AI orchestration is an experimental feature in the clnrm-ai crate.\n\
132 To use this feature, enable the 'ai' feature flag or use the clnrm-ai crate directly."
133 ))
134 }
135
136 Commands::AiPredict {
137 analyze_history: _,
138 predict_failures: _,
139 recommendations: _,
140 format: _,
141 } => {
142 Err(crate::error::CleanroomError::validation_error(
143 "AI predictive analytics is an experimental feature in the clnrm-ai crate.\n\
144 To use this feature, enable the 'ai' feature flag or use the clnrm-ai crate directly."
145 ))
146 }
147
148 Commands::AiOptimize {
149 execution_order: _,
150 resource_allocation: _,
151 parallel_execution: _,
152 auto_apply: _,
153 } => {
154 Err(crate::error::CleanroomError::validation_error(
155 "AI test optimization is an experimental feature in the clnrm-ai crate.\n\
156 To use this feature, enable the 'ai' feature flag or use the clnrm-ai crate directly."
157 ))
158 }
159
160 Commands::AiReal { analyze: _ } => {
161 Err(crate::error::CleanroomError::validation_error(
162 "AI real-time analysis is an experimental feature in the clnrm-ai crate.\n\
163 To use this feature, enable the 'ai' feature flag or use the clnrm-ai crate directly."
164 ))
165 }
166
167 Commands::Health { verbose } => system_health_check(verbose).await,
168
169 Commands::AiMonitor {
170 interval: _,
171 anomaly_threshold: _,
172 ai_alerts: _,
173 anomaly_detection: _,
174 proactive_healing: _,
175 webhook_url: _,
176 } => {
177 Err(crate::error::CleanroomError::validation_error(
178 "AI monitoring is an experimental feature in the clnrm-ai crate.\n\
179 To use this feature, enable the 'ai' feature flag or use the clnrm-ai crate directly."
180 ))
181 }
182
183 Commands::Marketplace { command } => {
184 let marketplace = crate::marketplace::Marketplace::default().await?;
185 crate::marketplace::commands::execute_marketplace_command(&marketplace, command).await
186 }
187 };
188
189 if let Err(e) = result {
190 error!("Command failed: {}", e);
191 std::process::exit(1);
192 }
193
194 Ok(())
195}
196
197pub use commands::*;
199pub use types::*;
200pub use utils::*;