use anyhow::Result;
use pmat::cli::handlers::satd_handler::{handle_analyze_satd, SatdAnalysisConfig};
use pmat::cli::{SatdOutputFormat, SatdSeverity};
use std::path::PathBuf;
#[tokio::main]
async fn main() -> Result<()> {
println!("🔍 Analyze SATD (Technical Debt) Example\n");
println!("Example 1: Basic SATD analysis");
println!("{}", "=".repeat(60));
let config = SatdAnalysisConfig {
path: PathBuf::from("."),
format: SatdOutputFormat::Summary,
severity: None, critical_only: false, include_tests: false, strict: false, evolution: false, days: 30, metrics: true, output: None, top_files: 10, fail_on_violation: false, timeout: 60, include: vec![], exclude: vec![], extended: false, };
match handle_analyze_satd(config).await {
Ok(_) => println!("✅ SATD analysis completed\n"),
Err(e) => println!("❌ Analysis failed: {}\n", e),
}
println!("\nExample 2: Extended mode - Detect AI-generated euphemisms");
println!("{}", "=".repeat(60));
println!("Extended mode detects hidden technical debt:");
println!(" - placeholder, stub, simplified");
println!(" - mock, dummy, fake, hardcoded");
println!(" - 'for now', WIP, skip/bypass\n");
let extended_config = SatdAnalysisConfig {
path: PathBuf::from("src"),
format: SatdOutputFormat::Summary,
severity: None,
critical_only: false,
include_tests: false,
strict: false,
evolution: false,
days: 30,
metrics: true,
output: None,
top_files: 10,
fail_on_violation: false,
timeout: 120,
include: vec![],
exclude: vec![],
extended: true, };
match handle_analyze_satd(extended_config).await {
Ok(_) => println!("✅ Extended SATD analysis completed!\n"),
Err(e) => println!("❌ Extended analysis failed: {}\n", e),
}
println!("\nExample 3: Zero-tolerance mode for CI/CD");
println!("{}", "=".repeat(60));
let ci_config = SatdAnalysisConfig {
path: PathBuf::from("."),
format: SatdOutputFormat::Json, severity: None,
critical_only: false,
include_tests: false,
strict: true, evolution: false,
days: 30,
metrics: true,
output: None,
top_files: 0, fail_on_violation: false, timeout: 60,
include: vec![],
exclude: vec!["target/**".to_string()],
extended: true, };
match handle_analyze_satd(ci_config).await {
Ok(_) => println!("✅ CI/CD analysis completed!"),
Err(e) => println!("❌ Analysis failed: {}", e),
}
println!("Note: In real CI, use --fail-on-violation to exit(1) on any debt found");
println!("\nExample 4: Check for critical technical debt only");
println!("{}", "=".repeat(60));
let critical_config = SatdAnalysisConfig {
path: PathBuf::from("."),
format: SatdOutputFormat::Summary,
severity: Some(SatdSeverity::Critical),
critical_only: true,
include_tests: false,
strict: false,
evolution: false,
days: 30,
metrics: false,
output: None,
top_files: 5,
fail_on_violation: false,
timeout: 60,
include: vec![],
exclude: vec![],
extended: false,
};
match handle_analyze_satd(critical_config).await {
Ok(_) => println!("✅ Critical debt analysis completed!"),
Err(e) => println!("❌ Critical debt analysis failed: {}", e),
}
println!("\nExample 5: Track debt evolution over time");
println!("{}", "=".repeat(60));
let evolution_config = SatdAnalysisConfig {
path: PathBuf::from("."),
format: SatdOutputFormat::Summary,
severity: None,
critical_only: false,
include_tests: false,
strict: false,
evolution: true, days: 60, metrics: true,
output: None,
top_files: 10,
fail_on_violation: false,
timeout: 60,
include: vec![],
exclude: vec![],
extended: false,
};
match handle_analyze_satd(evolution_config).await {
Ok(_) => println!("✅ Debt evolution analysis complete!"),
Err(e) => println!("❌ Evolution analysis failed: {}", e),
}
println!("\nExample 6: Save detailed SATD report with filters");
println!("{}", "=".repeat(60));
let output_path = PathBuf::from("satd-report.json");
let report_config = SatdAnalysisConfig {
path: PathBuf::from("."),
format: SatdOutputFormat::Json,
severity: None,
critical_only: false,
include_tests: true, strict: true,
evolution: false,
days: 30,
metrics: true,
output: Some(output_path.clone()),
top_files: 0, fail_on_violation: false,
timeout: 60,
include: vec!["src/**/*.rs".to_string()], exclude: vec!["**/tests/**".to_string()], extended: true, };
match handle_analyze_satd(report_config).await {
Ok(_) => println!("✅ SATD report saved to: {}", output_path.display()),
Err(e) => println!("❌ Failed to save report: {}", e),
}
println!("\nExample 7: CLI Usage Reference");
println!("{}", "=".repeat(60));
println!("# Standard SATD detection");
println!("pmat analyze satd --path src/");
println!();
println!("# Extended mode (detect euphemisms like 'placeholder', 'stub')");
println!("pmat analyze satd --extended --path src/");
println!();
println!("# CI/CD zero-tolerance (fail on any debt)");
println!("pmat analyze satd --strict --extended --fail-on-violation");
println!();
println!("# Critical debt only");
println!("pmat analyze satd --critical-only --fail-on-violation");
println!("\nExample 8: GitHub Actions CI integration");
println!("{}", "=".repeat(60));
println!("```yaml");
println!("- name: Check for technical debt");
println!(" run: |");
println!(" # Fail if ANY technical debt is found (including euphemisms)");
println!(" pmat analyze satd \\");
println!(" --extended \\");
println!(" --fail-on-violation \\");
println!(" --format json");
println!();
println!(" # Or allow some debt but fail on critical");
println!(" pmat analyze satd \\");
println!(" --critical-only \\");
println!(" --fail-on-violation");
println!("```");
println!("This enforces a zero-tolerance policy for technical debt.");
println!("\n🎉 SATD analysis examples completed!");
Ok(())
}