use std::io::Write;
use crate::analyzer::stats::AnalysisResult;
use crate::config::SortBy;
use crate::error::Result;
use crate::insight::estimation::{EstimationComparison, EstimationReport};
use crate::insight::health::HealthReport;
use crate::insight::hotspot::HotspotReport;
use crate::insight::trend::TrendReport;
#[derive(Debug, Clone)]
pub enum Report {
Analysis(AnalysisResult),
Health(HealthReport),
Hotspot(HotspotReport),
Trend(TrendReport),
Estimation(EstimationReport),
EstimationComparison(EstimationComparison),
}
pub trait OutputFormat: Send + Sync {
fn name(&self) -> &'static str;
fn extension(&self) -> &'static str;
fn write(&self, report: &Report, options: &OutputOptions, writer: &mut dyn Write)
-> Result<()>;
}
#[derive(Debug, Clone)]
pub struct OutputOptions {
pub summary_only: bool,
pub sort_by: SortBy,
pub top_n: Option<usize>,
pub colorize: bool,
pub show_git_info: bool,
}
impl Default for OutputOptions {
fn default() -> Self {
Self {
summary_only: false,
sort_by: SortBy::Lines,
top_n: None,
colorize: true,
show_git_info: false,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_output_options_default() {
let options = OutputOptions::default();
assert!(!options.summary_only);
assert!(matches!(options.sort_by, SortBy::Lines));
assert!(options.top_n.is_none());
assert!(options.colorize);
assert!(!options.show_git_info);
}
#[test]
fn test_output_options_custom() {
let options = OutputOptions {
summary_only: true,
sort_by: SortBy::Code,
top_n: Some(10),
colorize: false,
show_git_info: true,
};
assert!(options.summary_only);
assert!(matches!(options.sort_by, SortBy::Code));
assert_eq!(options.top_n, Some(10));
assert!(!options.colorize);
assert!(options.show_git_info);
}
}