pub mod human;
pub mod json;
use clap::ValueEnum;
use std::io::Write;
use crate::error::ProxyResult;
use crate::introspection::ServerSpec;
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum OutputFormat {
Human,
Json,
JsonPretty,
Yaml,
}
pub trait OutputFormatter {
fn write_spec(&self, spec: &ServerSpec, writer: &mut dyn Write) -> ProxyResult<()>;
fn write_error(&self, error: &str, writer: &mut dyn Write) -> ProxyResult<()>;
fn write_success(&self, message: &str, writer: &mut dyn Write) -> ProxyResult<()>;
}
#[must_use]
#[allow(clippy::match_same_arms)]
pub fn get_formatter(format: OutputFormat) -> Box<dyn OutputFormatter> {
match format {
OutputFormat::Human => Box::new(human::HumanFormatter::new()),
OutputFormat::Json => Box::new(json::JsonFormatter::new(false)),
OutputFormat::JsonPretty => Box::new(json::JsonFormatter::new(true)),
OutputFormat::Yaml => Box::new(json::JsonFormatter::new(true)), }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_formatter_creation() {
let _formatter = get_formatter(OutputFormat::Human);
let _formatter = get_formatter(OutputFormat::Json);
let _formatter = get_formatter(OutputFormat::JsonPretty);
}
}