arborist_cli/output/
mod.rs1pub mod csv_output;
2pub mod json;
3pub mod table;
4
5use arborist::FileReport;
6
7use crate::analysis;
8use crate::cli::{AnalyzeArgs, OutputFormat};
9use crate::error::ArboristError;
10
11pub fn write_output(
12 reports: &[FileReport],
13 args: &AnalyzeArgs,
14 _threshold_exceeded: bool,
15) -> Result<(), ArboristError> {
16 let use_flat_mode = args.sort.is_some() || args.top.is_some();
17
18 if use_flat_mode {
19 let mut flat = analysis::flatten_reports(reports);
20
21 if let Some(ref sort) = args.sort {
22 analysis::sort_and_top(&mut flat, sort, args.top);
23 } else if let Some(top) = args.top {
24 analysis::sort_and_top(&mut flat, &crate::cli::SortMetric::Cognitive, Some(top));
26 }
27
28 if args.exceeds_only
30 && let Some(threshold) = args.threshold
31 {
32 flat.retain(|f| f.cognitive > threshold);
33 }
34
35 match args.format {
36 OutputFormat::Table => table::write_flat(&flat, args),
37 OutputFormat::Json => json::write_flat(&flat),
38 OutputFormat::Csv => csv_output::write_flat(&flat),
39 }
40 } else {
41 match args.format {
42 OutputFormat::Table => table::write_reports(reports, args),
43 OutputFormat::Json => json::write_reports(reports),
44 OutputFormat::Csv => csv_output::write_reports(reports),
45 }
46 }
47}