mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
variable renames
This commit is contained in:
parent
e26fd0721b
commit
318e45e2ad
2 changed files with 21 additions and 17 deletions
24
jrnl/args.py
24
jrnl/args.py
|
@ -27,19 +27,23 @@ def deserialize_config_args(input: list) -> dict:
|
|||
:return: A single level dict of the configuration keys in dot-notation and their respective desired values
|
||||
:rtype: dict
|
||||
"""
|
||||
|
||||
assert len(input) == 2
|
||||
runtime_modifications = {}
|
||||
|
||||
l = input[0]
|
||||
r = input[1]
|
||||
r = r.strip()
|
||||
if r.isdigit():
|
||||
r = int(r)
|
||||
elif r.lower() == "true":
|
||||
r = True
|
||||
elif r.lower() == "false":
|
||||
r = False
|
||||
runtime_modifications[l] = r
|
||||
cfg_key = input[0]
|
||||
cfg_value = input[1]
|
||||
cfg_value = cfg_value.strip()
|
||||
|
||||
# Convert numbers and booleans
|
||||
if cfg_value.isdigit():
|
||||
cfg_value = int(cfg_value)
|
||||
elif cfg_value.lower() == "true":
|
||||
cfg_value = True
|
||||
elif cfg_value.lower() == "false":
|
||||
cfg_value = False
|
||||
|
||||
runtime_modifications[cfg_key] = cfg_value
|
||||
return runtime_modifications
|
||||
|
||||
|
||||
|
|
|
@ -11,13 +11,13 @@ def apply_overrides(overrides: list, base_config: dict) -> dict:
|
|||
"""
|
||||
config = base_config.copy()
|
||||
for pairs in overrides:
|
||||
k, v = list(pairs.items())[0]
|
||||
nodes = k.split(".")
|
||||
config = _recursively_apply(config, nodes, v)
|
||||
key_as_dots, override_value = list(pairs.items())[0]
|
||||
keys = key_as_dots.split(".")
|
||||
config = _recursively_apply(config, keys, override_value)
|
||||
return config
|
||||
|
||||
|
||||
def _recursively_apply(config: dict, nodes: list, override_value) -> dict:
|
||||
def _recursively_apply(tree: dict, nodes: list, override_value) -> dict:
|
||||
"""Recurse through configuration and apply overrides at the leaf of the config tree
|
||||
|
||||
Credit to iJames on SO: https://stackoverflow.com/a/47276490 for algorithm
|
||||
|
@ -29,12 +29,12 @@ def _recursively_apply(config: dict, nodes: list, override_value) -> dict:
|
|||
"""
|
||||
key = nodes[0]
|
||||
if len(nodes) == 1:
|
||||
config[key] = override_value
|
||||
tree[key] = override_value
|
||||
else:
|
||||
next_key = nodes[1:]
|
||||
_recursively_apply(_get_config_node(config, key), next_key, override_value)
|
||||
_recursively_apply(_get_config_node(tree, key), next_key, override_value)
|
||||
|
||||
return config
|
||||
return tree
|
||||
|
||||
|
||||
def _get_config_node(config: dict, key: str):
|
||||
|
|
Loading…
Add table
Reference in a new issue