use anyhow::Result;
use pmat::cli::handlers::complexity_handlers::handle_analyze_complexity;
use pmat::cli::ComplexityOutputFormat;
use std::path::PathBuf;
#[tokio::main]
async fn main() -> Result<()> {
println!("🔍 Analyze Complexity Example\n");
println!("Example 1: Basic complexity analysis of current directory");
println!("{}", "=".repeat(60));
let result = handle_analyze_complexity(
PathBuf::from("."),
None, vec![], None, ComplexityOutputFormat::Full,
None, None, None, vec![], false, 10, false, 60, )
.await;
match result {
Ok(_) => println!("✅ Analysis completed successfully\n"),
Err(e) => println!("❌ Analysis failed: {}\n", e),
}
println!("\nExample 2: CI/CD mode with strict thresholds and exit code");
println!("{}", "=".repeat(60));
let strict_result = handle_analyze_complexity(
PathBuf::from("."),
None,
vec![],
None,
ComplexityOutputFormat::Json, None,
Some(10), Some(5), vec![String::from("src/**/*.rs")], false,
5, false, 60, )
.await;
match strict_result {
Ok(_) => println!("✅ Analysis completed!"),
Err(e) => {
println!("❌ Analysis failed: {}", e);
return Err(e);
}
}
println!("Note: In real CI, you would use --fail-on-violation to exit(1) on violations");
println!("\nExample 3: Analyzing specific files with custom thresholds");
println!("{}", "=".repeat(60));
let specific_files = vec![
PathBuf::from("src/main.rs"),
PathBuf::from("src/cli/mod.rs"),
];
let file_result = handle_analyze_complexity(
PathBuf::from("."),
None,
specific_files,
None,
ComplexityOutputFormat::Summary,
None,
Some(15), Some(10),
vec![],
false,
0, false,
60, )
.await;
match file_result {
Ok(_) => println!("✅ File analysis complete!"),
Err(e) => println!("❌ File analysis failed: {}", e),
}
println!("\nExample 4: GitHub Actions CI integration");
println!("{}", "=".repeat(60));
println!("In your GitHub Actions workflow, use:");
println!("```yaml");
println!("- name: Check code complexity");
println!(" run: |");
println!(" pmat analyze complexity \\");
println!(" --max-cyclomatic 15 \\");
println!(" --max-cognitive 10 \\");
println!(" --fail-on-violation \\");
println!(" --format json");
println!("```");
println!("This will fail the CI build if any function exceeds the thresholds.");
println!("\nExample 5: ML-based complexity scoring");
println!("{}", "=".repeat(60));
println!("Use the --ml flag for ML-based quality scoring (GH-97):");
println!("```bash");
println!("# Standard analysis with ML-based scoring");
println!("pmat analyze complexity --ml");
println!();
println!("# Combined with thresholds");
println!("pmat analyze complexity --ml --max-cyclomatic 15 --fail-on-violation");
println!("```");
println!("ML scoring uses aprender LinearRegression for evidence-based quality predictions.");
println!("\n🎉 Complexity analysis examples completed!");
Ok(())
}