ferrous_forge/commands/
validate.rs1use crate::{
4 Result,
5 validation::RustValidator,
6 doc_coverage,
7 formatting,
8 security,
9};
10use console::style;
11use std::path::PathBuf;
12
13pub async fn execute(path: Option<PathBuf>) -> Result<()> {
15 let project_path = path.unwrap_or_else(|| std::env::current_dir().unwrap_or_default());
16
17 println!("{}", style("🦀 Running Ferrous Forge validation...").bold().cyan());
18 println!("📁 Project: {}", project_path.display());
19 println!();
20
21 let validator = RustValidator::new(project_path.clone())?;
23
24 let violations = validator.validate_project().await?;
26
27 let report = validator.generate_report(&violations);
29 println!("{}", report);
30
31 println!("{}", style("🔧 Running Clippy with strict configuration...").bold().yellow());
33 let clippy_result = validator.run_clippy().await?;
34
35 if !clippy_result.success {
36 println!("{}", style("❌ Clippy found issues:").red());
37 println!("{}", clippy_result.output);
38 } else {
39 println!("{}", style("✅ Clippy validation passed!").green());
40 }
41
42 println!();
44 println!("{}", style("📚 Checking documentation coverage...").bold().yellow());
45 match doc_coverage::check_documentation_coverage(&project_path).await {
46 Ok(coverage) => {
47 println!("{}", coverage.report());
48 if coverage.coverage_percent < 80.0 {
49 println!("{}", style("⚠️ Documentation coverage below 80%").yellow());
50 }
51 }
52 Err(e) => {
53 println!("{}", style(format!("⚠️ Could not check documentation: {}", e)).yellow());
54 }
55 }
56
57 println!();
59 println!("{}", style("📝 Checking code formatting...").bold().yellow());
60 match formatting::check_formatting(&project_path).await {
61 Ok(format_result) => {
62 println!("{}", format_result.report());
63 }
64 Err(e) => {
65 println!("{}", style(format!("⚠️ Could not check formatting: {}", e)).yellow());
66 }
67 }
68
69 println!();
71 println!("{}", style("🔒 Running security audit...").bold().yellow());
72 match security::run_security_audit(&project_path).await {
73 Ok(audit_report) => {
74 println!("{}", audit_report.report());
75 }
76 Err(e) => {
77 println!("{}", style(format!("⚠️ Could not run security audit: {}", e)).yellow());
78 }
79 }
80
81 if !violations.is_empty() || !clippy_result.success {
83 std::process::exit(1);
84 } else {
85 println!();
86 println!("{}", style("🎉 All validations passed! Code meets Ferrous Forge standards.").bold().green());
87 }
88
89 Ok(())
90}