use std::collections::HashMap;
use std::str::FromStr;
use anyhow::{anyhow, Result};
use strum_macros::EnumIter;
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 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(anyhow!("Config '{}' not found", self.as_ref()));
match self {
Self::SkipConfigValidation => get_result
.and_then(|v| bool::from_str(v).map_err(|e| anyhow!(e)))
.map(HudiConfigValue::Boolean),
}
}
}