pub mod json;
pub mod plain;
pub mod sarif;
use crate::analyzer::kubelint::lint::LintResult;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum OutputFormat {
#[default]
Plain,
Json,
Sarif,
GitHub,
}
impl OutputFormat {
pub fn parse(s: &str) -> Option<Self> {
match s.to_lowercase().as_str() {
"plain" | "text" => Some(Self::Plain),
"json" => Some(Self::Json),
"sarif" => Some(Self::Sarif),
"github" | "github-actions" => Some(Self::GitHub),
_ => None,
}
}
}
pub fn format_result_to_string(result: &LintResult, format: OutputFormat) -> String {
match format {
OutputFormat::Plain => plain::format(result),
OutputFormat::Json => json::format(result),
OutputFormat::Sarif => sarif::format(result),
OutputFormat::GitHub => plain::format_github(result),
}
}
pub fn format_result(result: &LintResult, format: OutputFormat) {
print!("{}", format_result_to_string(result, format));
}