use std::collections::HashMap;
use std::fmt::Display;
use std::str::FromStr;
use strum_macros::EnumIter;
use crate::config::error::ConfigError::{NotFound, ParseBool};
use crate::config::Result;
use crate::config::{ConfigParser, HudiConfigValue};
#[derive(Clone, Debug, PartialEq, Eq, Hash, EnumIter)]
pub enum HudiInternalConfig {
SkipConfigValidation,
}
impl AsRef<str> for HudiInternalConfig {
fn as_ref(&self) -> &str {
match self {
Self::SkipConfigValidation => "hoodie.internal.skip.config.validation",
}
}
}
impl Display for HudiInternalConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_ref())
}
}
impl ConfigParser for HudiInternalConfig {
type Output = HudiConfigValue;
fn default_value(&self) -> Option<HudiConfigValue> {
match self {
Self::SkipConfigValidation => Some(HudiConfigValue::Boolean(false)),
}
}
fn parse_value(&self, configs: &HashMap<String, String>) -> Result<Self::Output> {
let get_result = configs
.get(self.as_ref())
.map(|v| v.as_str())
.ok_or(NotFound(self.key()));
match self {
Self::SkipConfigValidation => get_result
.and_then(|v| {
bool::from_str(v).map_err(|e| ParseBool(self.key(), v.to_string(), e))
})
.map(HudiConfigValue::Boolean),
}
}
}