Skip to main content

ai_coding_shield/reporter/
mod.rs

1mod terminal;
2mod json;
3mod html;
4
5use anyhow::Result;
6use std::path::Path;
7
8use crate::types::AnalysisResult;
9
10pub struct Reporter {
11    format: ReportFormat,
12    show_safe: bool,
13}
14
15enum ReportFormat {
16    Terminal,
17    Json,
18    Html,
19}
20
21impl Reporter {
22    pub fn new(format: &str, show_safe: bool) -> Self {
23        let format = match format.to_lowercase().as_str() {
24            "json" => ReportFormat::Json,
25            "html" => ReportFormat::Html,
26            _ => ReportFormat::Terminal,
27        };
28
29        Self { format, show_safe }
30    }
31
32    pub fn report(&self, results: &[AnalysisResult], output: Option<&Path>) -> Result<()> {
33        match self.format {
34            ReportFormat::Terminal => terminal::report(results, self.show_safe),
35            ReportFormat::Json => json::report(results, output, self.show_safe),
36            ReportFormat::Html => html::report(results, output, self.show_safe),
37        }
38    }
39}