mirror of
https://github.com/dtomlinson91/panaetius.git
synced 2025-12-21 20:55:43 +00:00
feat: add ability to retrieve keys 3 levels deep
This commit is contained in:
@@ -147,15 +147,16 @@ class Config:
|
|||||||
if value is not None:
|
if value is not None:
|
||||||
return self.__get_config_value_env_var_override(value)
|
return self.__get_config_value_env_var_override(value)
|
||||||
|
|
||||||
if len(key.split(".")) > 2:
|
if len(key.split(".")) > 3:
|
||||||
raise KeyErrorTooDeepException(
|
raise KeyErrorTooDeepException(
|
||||||
f"Your key of {key} can only be 2 levels deep maximum. "
|
f"Your key of {key} can only be 3 levels deep maximum."
|
||||||
f"You have {len(key.split('.'))}"
|
|
||||||
)
|
)
|
||||||
if len(key.split(".")) == 1:
|
if len(key.split(".")) == 1:
|
||||||
return self.__get_config_value_key_split_once(key)
|
return self.__get_config_value_key_split_once(key)
|
||||||
if len(key.split(".")) == 2:
|
if len(key.split(".")) == 2:
|
||||||
return self.__get_config_value_key_split_twice(key)
|
return self.__get_config_value_key_split_twice(key)
|
||||||
|
if len(key.split(".")) == 3:
|
||||||
|
return self.__get_config_value_key_split_thrice(key)
|
||||||
raise KeyError()
|
raise KeyError()
|
||||||
|
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
@@ -172,6 +173,10 @@ class Config:
|
|||||||
section, name = key.lower().split(".")
|
section, name = key.lower().split(".")
|
||||||
return self.config[self.header_variable][section][name]
|
return self.config[self.header_variable][section][name]
|
||||||
|
|
||||||
|
def __get_config_value_key_split_thrice(self, key: str) -> Any:
|
||||||
|
section, name_0, name_1 = key.lower().split(".")
|
||||||
|
return self.config[self.header_variable][section][name_0][name_1]
|
||||||
|
|
||||||
def __get_config_value_missing_key_value_is_none(self, default: Any) -> Any:
|
def __get_config_value_missing_key_value_is_none(self, default: Any) -> Any:
|
||||||
return self.__load_default_value(default)
|
return self.__load_default_value(default)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user