use crate::output::output::Output;
use crate::Result;
use clap::ValueEnum;
use miette::{Context, IntoDiagnostic};
#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)]
pub enum OutputFormat {
Plain,
Json,
}
impl OutputFormat {
pub fn println_value<T>(&self, t: &T) -> Result<()>
where
T: Output + serde::Serialize,
{
let output = match self {
OutputFormat::Plain => t
.output()
.into_diagnostic()
.context("Failed to serialize output")?,
OutputFormat::Json => serde_json::to_string_pretty(t)
.into_diagnostic()
.context("Failed to serialize output")?,
};
println!("{output}");
Ok(())
}
}