use crate::cli::OutputFormat;
use crate::error::{OlError, OL_4270_CONFIG_UNREADABLE};
use serde::Serialize;
pub fn render<T: Serialize>(format: OutputFormat, value: &T) -> Result<(), OlError> {
match format {
OutputFormat::Json => {
let s = serde_json::to_string_pretty(value)
.map_err(|e| OlError::new(OL_4270_CONFIG_UNREADABLE, format!("json: {e}")))?;
println!("{s}");
Ok(())
}
OutputFormat::Yaml => {
let s = serde_yaml::to_string(value)
.map_err(|e| OlError::new(OL_4270_CONFIG_UNREADABLE, format!("yaml: {e}")))?;
print!("{s}");
Ok(())
}
OutputFormat::Table | OutputFormat::Sarif => {
let s = serde_json::to_string_pretty(value)
.map_err(|e| OlError::new(OL_4270_CONFIG_UNREADABLE, format!("json: {e}")))?;
println!("{s}");
Ok(())
}
}
}