use super::*;
pub trait ConfigValue: Sized {
fn from_config_str(raw: &str) -> AppResult<Self>;
}
impl ConfigValue for FormatArg {
fn from_config_str(raw: &str) -> AppResult<Self> {
match raw {
"txt" => Ok(Self::Txt),
"srt" => Ok(Self::Srt),
"vtt" => Ok(Self::Vtt),
other => Err(AppError::Config(format!(
"{} `{other}`",
t(Message::ConfigInvalidFormat)
))),
}
}
}
impl ConfigValue for LogLevelArg {
fn from_config_str(raw: &str) -> AppResult<Self> {
match raw {
"error" => Ok(Self::Error),
"warn" => Ok(Self::Warn),
"info" => Ok(Self::Info),
"debug" => Ok(Self::Debug),
"trace" => Ok(Self::Trace),
other => Err(AppError::Config(format!(
"{} `{other}`",
t(Message::ConfigInvalidLogLevel)
))),
}
}
}
impl ConfigValue for LogFormatArg {
fn from_config_str(raw: &str) -> AppResult<Self> {
match raw {
"text" => Ok(Self::Text),
"json" => Ok(Self::Json),
other => Err(AppError::Config(format!(
"{} `{other}`",
t(Message::ConfigInvalidLogFormat)
))),
}
}
}
impl ConfigValue for ColorArg {
fn from_config_str(raw: &str) -> AppResult<Self> {
match raw {
"auto" => Ok(Self::Auto),
"always" => Ok(Self::Always),
"never" => Ok(Self::Never),
other => Err(AppError::Config(format!(
"{} `{other}`",
t(Message::ConfigInvalidColor)
))),
}
}
}
impl ConfigValue for ProviderChoice {
fn from_config_str(raw: &str) -> AppResult<Self> {
match raw {
"auto" => Ok(Self::Auto),
"provider-decopy" => Ok(Self::ProviderDecopy),
"provider-noiz" => Ok(Self::ProviderNoiz),
other => Err(AppError::Config(format!(
"{} `{other}`",
t(Message::ConfigInvalidProvider)
))),
}
}
}
impl ConfigValue for LanguageArg {
fn from_config_str(raw: &str) -> AppResult<Self> {
Self::parse(raw).map_err(|e| AppError::Config(e.to_string()))
}
}
impl ConfigValue for Language {
fn from_config_str(raw: &str) -> AppResult<Self> {
Self::from_tag(raw).ok_or_else(|| {
AppError::Config(format!(
"{} `{raw}` ({})",
t(Message::ConfigInvalidUiLang),
Self::compiled_tags()
))
})
}
}