codelens_core/output/
format.rs1use std::io::Write;
4
5use crate::analyzer::stats::AnalysisResult;
6use crate::config::SortBy;
7use crate::error::Result;
8use crate::insight::health::HealthReport;
9use crate::insight::hotspot::HotspotReport;
10use crate::insight::trend::TrendReport;
11
12#[derive(Debug, Clone)]
14pub enum Report {
15 Analysis(AnalysisResult),
16 Health(HealthReport),
17 Hotspot(HotspotReport),
18 Trend(TrendReport),
19}
20
21pub trait OutputFormat: Send + Sync {
23 fn name(&self) -> &'static str;
25
26 fn extension(&self) -> &'static str;
28
29 fn write(&self, report: &Report, options: &OutputOptions, writer: &mut dyn Write)
31 -> Result<()>;
32}
33
34#[derive(Debug, Clone)]
36pub struct OutputOptions {
37 pub summary_only: bool,
39 pub sort_by: SortBy,
41 pub top_n: Option<usize>,
43 pub colorize: bool,
45 pub show_git_info: bool,
47}
48
49impl Default for OutputOptions {
50 fn default() -> Self {
51 Self {
52 summary_only: false,
53 sort_by: SortBy::Lines,
54 top_n: None,
55 colorize: true,
56 show_git_info: false,
57 }
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_output_options_default() {
67 let options = OutputOptions::default();
68 assert!(!options.summary_only);
69 assert!(matches!(options.sort_by, SortBy::Lines));
70 assert!(options.top_n.is_none());
71 assert!(options.colorize);
72 assert!(!options.show_git_info);
73 }
74
75 #[test]
76 fn test_output_options_custom() {
77 let options = OutputOptions {
78 summary_only: true,
79 sort_by: SortBy::Code,
80 top_n: Some(10),
81 colorize: false,
82 show_git_info: true,
83 };
84 assert!(options.summary_only);
85 assert!(matches!(options.sort_by, SortBy::Code));
86 assert_eq!(options.top_n, Some(10));
87 assert!(!options.colorize);
88 assert!(options.show_git_info);
89 }
90}