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