use anyhow::Result;
use pmat::cli::analysis_utilities::handle_quality_gate;
use pmat::cli::enums::{QualityCheckType, QualityGateOutputFormat};
use std::path::PathBuf;
#[tokio::main]
async fn main() -> Result<()> {
println!("🔍 Quality Gate Example\n");
println!("Example 1: Running all quality checks on current directory");
println!("{}", "=".repeat(60));
let result = handle_quality_gate(
PathBuf::from("."),
None, QualityGateOutputFormat::Summary,
false, vec![], 15.0, 2.0, 50, false, None, false, )
.await;
match result {
Ok(_) => println!("✅ Quality gate passed!\n"),
Err(e) => println!("❌ Quality gate failed: {}\n", e),
}
println!("\nExample 2: Running specific checks with stricter thresholds");
println!("{}", "=".repeat(60));
let strict_result = handle_quality_gate(
PathBuf::from("."),
None,
QualityGateOutputFormat::Human,
false, vec![
QualityCheckType::Complexity,
QualityCheckType::DeadCode,
QualityCheckType::Satd,
],
5.0, 3.0, 20, false,
None,
false,
)
.await;
match strict_result {
Ok(_) => println!("✅ Strict quality gate passed!"),
Err(e) => println!("⚠️ Strict quality gate failed (expected): {}", e),
}
println!("\nExample 3: Analyzing a specific file");
println!("{}", "=".repeat(60));
let file_result = handle_quality_gate(
PathBuf::from("."),
Some(PathBuf::from("src/main.rs")),
QualityGateOutputFormat::Json,
false,
vec![QualityCheckType::Complexity],
15.0,
2.0,
30, false,
None,
false,
)
.await;
match file_result {
Ok(_) => println!("✅ Single file analysis complete!"),
Err(e) => println!("❌ Single file analysis failed: {}", e),
}
println!("\nExample 4: Saving quality gate results to file");
println!("{}", "=".repeat(60));
let output_path = PathBuf::from("quality-report.json");
let output_result = handle_quality_gate(
PathBuf::from("."),
None,
QualityGateOutputFormat::Json,
false,
vec![],
15.0,
2.0,
50,
true, Some(output_path.clone()),
false,
)
.await;
match output_result {
Ok(_) => println!("✅ Quality report saved to: {}", output_path.display()),
Err(e) => println!("❌ Failed to save report: {}", e),
}
println!("\n🎉 Quality gate examples completed!");
Ok(())
}