syncable_cli/analyzer/kubelint/formatter/
mod.rs1pub mod json;
4pub mod plain;
5pub mod sarif;
6
7use crate::analyzer::kubelint::lint::LintResult;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
11pub enum OutputFormat {
12 #[default]
14 Plain,
15 Json,
17 Sarif,
19 GitHub,
21}
22
23impl OutputFormat {
24 pub fn parse(s: &str) -> Option<Self> {
26 match s.to_lowercase().as_str() {
27 "plain" | "text" => Some(Self::Plain),
28 "json" => Some(Self::Json),
29 "sarif" => Some(Self::Sarif),
30 "github" | "github-actions" => Some(Self::GitHub),
31 _ => None,
32 }
33 }
34}
35
36pub fn format_result_to_string(result: &LintResult, format: OutputFormat) -> String {
38 match format {
39 OutputFormat::Plain => plain::format(result),
40 OutputFormat::Json => json::format(result),
41 OutputFormat::Sarif => sarif::format(result),
42 OutputFormat::GitHub => plain::format_github(result),
43 }
44}
45
46pub fn format_result(result: &LintResult, format: OutputFormat) {
48 print!("{}", format_result_to_string(result, format));
49}