summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2023-06-20 05:45:25 +0300
committerMaxim Devaev <[email protected]>2023-06-20 05:45:25 +0300
commita74044b086498cae1d6aed7cbf624e0b95e4f247 (patch)
tree376c184e24b0a01e23cd633874ea1039df87a6c0 /kvmd
parentdb3f6220238da8138c670924a074477987790fbe (diff)
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py2
-rw-r--r--kvmd/yamlconf/merger.py27
2 files changed, 14 insertions, 15 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 31847bc3..1a8acad9 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -179,7 +179,7 @@ def _init_config(config_path: str, override_options: list[str], **load_flags: bo
scheme = _get_config_scheme()
try:
yaml_merge(raw_config, (raw_config.pop("override", {}) or {}))
- yaml_merge(raw_config, build_raw_from_options(override_options), "raw command line options")
+ yaml_merge(raw_config, build_raw_from_options(override_options), "raw CLI options")
_patch_raw(raw_config)
config = make_config(raw_config, scheme)
diff --git a/kvmd/yamlconf/merger.py b/kvmd/yamlconf/merger.py
index 51a168c8..a11ff3aa 100644
--- a/kvmd/yamlconf/merger.py
+++ b/kvmd/yamlconf/merger.py
@@ -19,30 +19,29 @@
# #
# ========================================================================== #
-from typing import Optional
-
# =====
-def _merge(dest: dict, src: dict) -> None:
- for key in src:
- if key in dest:
- if isinstance(dest[key], dict) and isinstance(src[key], dict):
- _merge(dest[key], src[key])
- continue
- dest[key] = src[key]
-
-
-def yaml_merge(dest: dict, src: dict, source_name: Optional[str]=None) -> None:
+def yaml_merge(dest: dict, src: dict, src_name: str="") -> None:
""" Merges the source dictionary into the destination dictionary. """
# Checking if destination is None
if dest is None:
# We can't merge into a None
- raise ValueError(f"Could not merge {source_name} into None. The destination cannot be None")
+ raise ValueError(f"Could not merge {src_name or 'config'} into None. The destination cannot be None")
# Checking if source is None or empty
- if src is None:
+ if not src:
# If src is None or empty, there's nothing to merge
return
_merge(dest, src)
+
+
+# ======
+def _merge(dest: dict, src: dict) -> None:
+ for key in src:
+ if key in dest:
+ if isinstance(dest[key], dict) and isinstance(src[key], dict):
+ _merge(dest[key], src[key])
+ continue
+ dest[key] = src[key]