Skip to main content

oratos_report/
lib.rs

1//! Report formatters for Oratos audit results.
2
3mod console;
4mod html;
5mod json;
6mod markdown;
7mod sarif;
8
9pub use console::format_console;
10pub use html::format_html;
11pub use json::format_json;
12pub use markdown::format_markdown;
13pub use sarif::format_sarif;
14
15use oratos_core::AuditReport;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum ReportFormat {
19    Console,
20    Json,
21    Markdown,
22    Html,
23    Sarif,
24}
25
26impl ReportFormat {
27    pub fn parse(s: &str) -> Option<Self> {
28        match s.to_lowercase().as_str() {
29            "console" => Some(Self::Console),
30            "json" => Some(Self::Json),
31            "markdown" | "md" => Some(Self::Markdown),
32            "html" => Some(Self::Html),
33            "sarif" => Some(Self::Sarif),
34            _ => None,
35        }
36    }
37
38    pub fn render(&self, report: &AuditReport) -> String {
39        match self {
40            Self::Console => format_console(report),
41            Self::Json => format_json(report),
42            Self::Markdown => format_markdown(report),
43            Self::Html => format_html(report),
44            Self::Sarif => format_sarif(report),
45        }
46    }
47}