use bunsen::errors::{
BunsenError,
BunsenResult,
};
use serde::Serialize;
#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum Format {
#[value(alias = "yaml")]
Yml,
Json,
}
impl Format {
pub fn render<T: Serialize>(
self,
value: &T,
what: &str,
) -> BunsenResult<String> {
match self {
Format::Yml => serde_saphyr::to_string(value)
.map_err(|e| BunsenError::internal(format!("render {what} as YAML: {e}"))),
Format::Json => serde_json::to_string(value)
.map(|json| json + "\n")
.map_err(|e| BunsenError::internal(format!("render {what} as JSON: {e}"))),
}
}
}