use {
std::str::FromStr,
thiserror::Error,
};
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub enum Output {
Raw,
#[default]
Tables,
Csv,
Json,
}
#[derive(Debug, Error)]
pub enum ParseOutputError {
#[error("unrecognized output {0:?}")]
UnrecognizedValue(String),
}
impl FromStr for Output {
type Err = ParseOutputError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value.to_lowercase().as_str() {
"r" | "raw" => Ok(Self::Raw),
"t" | "tbl" | "tables" => Ok(Self::Tables),
"c" | "csv" => Ok(Self::Csv),
"j" | "json" => Ok(Self::Json),
_ => Err(ParseOutputError::UnrecognizedValue(value.to_owned()))
}
}
}