use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Format {
Text,
Json,
Jsonl,
Sarif,
Markdown,
}
impl std::fmt::Display for Format {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let value = match self {
Self::Text => "text",
Self::Json => "json",
Self::Jsonl => "jsonl",
Self::Sarif => "sarif",
Self::Markdown => "markdown",
};
f.write_str(value)
}
}
impl Format {
#[must_use]
pub fn from_str_loose(s: &str) -> Option<Self> {
match s.to_ascii_lowercase().as_str() {
"json" => Some(Self::Json),
"jsonl" => Some(Self::Jsonl),
"sarif" => Some(Self::Sarif),
"markdown" | "md" => Some(Self::Markdown),
"text" => Some(Self::Text),
_ => None,
}
}
}