#![cfg_attr(coverage_nightly, coverage(off))]
use super::CommandDispatcher;
use crate::cli::handlers;
use crate::cli::OutputFormat;
use std::path::PathBuf;
impl CommandDispatcher {
#[allow(clippy::too_many_arguments, dead_code)]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub(crate) async fn execute_quality_gate_command(
project_path: Option<PathBuf>,
file: Option<PathBuf>,
format: OutputFormat,
fail_on_violation: bool,
checks: Vec<String>,
max_dead_code: Option<f64>,
min_entropy: Option<f64>,
max_complexity_p99: Option<usize>,
include_provability: bool,
output: Option<PathBuf>,
perf: bool,
) -> anyhow::Result<()> {
use crate::cli::enums::{QualityCheckType, QualityGateOutputFormat};
let qg_format = match format {
OutputFormat::Json => QualityGateOutputFormat::Json,
OutputFormat::Table => QualityGateOutputFormat::Summary,
OutputFormat::Yaml => QualityGateOutputFormat::Summary,
_ => QualityGateOutputFormat::Summary,
};
let quality_checks: Vec<QualityCheckType> = checks
.iter()
.filter_map(|s| match s.as_str() {
"dead_code" | "dead-code" => Some(QualityCheckType::DeadCode),
"complexity" => Some(QualityCheckType::Complexity),
"coverage" => Some(QualityCheckType::Coverage),
"sections" => Some(QualityCheckType::Sections),
"provability" => Some(QualityCheckType::Provability),
"satd" => Some(QualityCheckType::Satd),
"entropy" => Some(QualityCheckType::Entropy),
"security" => Some(QualityCheckType::Security),
"duplicates" => Some(QualityCheckType::Duplicates),
"all" => Some(QualityCheckType::All),
_ => None,
})
.collect();
let max_dead = max_dead_code.unwrap_or(0.1); let max_comp = max_complexity_p99.unwrap_or(20) as u32;
crate::cli::analysis_utilities::handle_quality_gate(
project_path.unwrap_or_else(|| PathBuf::from(".")),
file,
qg_format,
fail_on_violation,
quality_checks,
max_dead,
min_entropy,
max_comp,
include_provability,
output,
perf,
)
.await
}
#[allow(clippy::too_many_arguments)]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub(crate) async fn execute_report_command(
project_path: Option<PathBuf>,
report_format: crate::cli::enums::ReportOutputFormat,
include_visualizations: bool,
include_executive_summary: bool,
include_recommendations: bool,
analyses: Vec<String>,
confidence_threshold: Option<f64>,
output: Option<PathBuf>,
perf: bool,
text: bool,
markdown: bool,
csv: bool,
) -> anyhow::Result<()> {
use crate::cli::enums::AnalysisType;
let analysis_types: Vec<AnalysisType> = analyses
.iter()
.filter_map(|s| match s.as_str() {
"complexity" => Some(AnalysisType::Complexity),
"dead_code" | "dead-code" => Some(AnalysisType::DeadCode),
"duplication" => Some(AnalysisType::Duplication),
"technical_debt" | "technical-debt" => Some(AnalysisType::TechnicalDebt),
"big_o" | "big-o" => Some(AnalysisType::BigO),
"all" => Some(AnalysisType::All),
_ => None,
})
.collect();
let confidence = (confidence_threshold.unwrap_or(0.8) * 100.0) as u8;
handlers::enhanced_reporting_handlers::handle_generate_report(
project_path.unwrap_or_else(|| PathBuf::from(".")),
report_format,
text,
markdown,
csv,
include_visualizations,
include_executive_summary,
include_recommendations,
analysis_types,
confidence,
output,
perf,
)
.await
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod report_format_passthrough_tests {
use super::*;
use crate::cli::enums::ReportOutputFormat;
#[test]
fn test_execute_report_command_carries_the_declared_report_format() {
#[allow(clippy::type_complexity)]
fn accepts_declared_format<F, Fut>(_f: F)
where
F: Fn(
Option<PathBuf>,
ReportOutputFormat,
bool,
bool,
bool,
Vec<String>,
Option<f64>,
Option<PathBuf>,
bool,
bool,
bool,
bool,
) -> Fut,
{
}
accepts_declared_format(CommandDispatcher::execute_report_command);
}
#[test]
fn test_all_report_format_variants_are_distinguishable() {
let variants = [
ReportOutputFormat::Json,
ReportOutputFormat::Csv,
ReportOutputFormat::Markdown,
ReportOutputFormat::Text,
ReportOutputFormat::Html,
ReportOutputFormat::Pdf,
ReportOutputFormat::Dashboard,
];
let mut seen = std::collections::BTreeSet::new();
for v in &variants {
assert!(seen.insert(v.to_string()), "duplicate rendering for {v}");
}
assert_eq!(seen.len(), variants.len());
}
}