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
|
:return: A single level dict of the configuration keys in dot-notation and their respective desired values
|
||||||
:rtype: dict
|
:rtype: dict
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert len(input) == 2
|
assert len(input) == 2
|
||||||
runtime_modifications = {}
|
runtime_modifications = {}
|
||||||
|
|
||||||
l = input[0]
|
cfg_key = input[0]
|
||||||
r = input[1]
|
cfg_value = input[1]
|
||||||
r = r.strip()
|
cfg_value = cfg_value.strip()
|
||||||
if r.isdigit():
|
|
||||||
r = int(r)
|
# Convert numbers and booleans
|
||||||
elif r.lower() == "true":
|
if cfg_value.isdigit():
|
||||||
r = True
|
cfg_value = int(cfg_value)
|
||||||
elif r.lower() == "false":
|
elif cfg_value.lower() == "true":
|
||||||
r = False
|
cfg_value = True
|
||||||
runtime_modifications[l] = r
|
elif cfg_value.lower() == "false":
|
||||||
|
cfg_value = False
|
||||||
|
|
||||||
|
runtime_modifications[cfg_key] = cfg_value
|
||||||
return runtime_modifications
|
return runtime_modifications
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@ def apply_overrides(overrides: list, base_config: dict) -> dict:
|
||||||
"""
|
"""
|
||||||
config = base_config.copy()
|
config = base_config.copy()
|
||||||
for pairs in overrides:
|
for pairs in overrides:
|
||||||
k, v = list(pairs.items())[0]
|
key_as_dots, override_value = list(pairs.items())[0]
|
||||||
nodes = k.split(".")
|
keys = key_as_dots.split(".")
|
||||||
config = _recursively_apply(config, nodes, v)
|
config = _recursively_apply(config, keys, override_value)
|
||||||
return config
|
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
|
"""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
|
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]
|
key = nodes[0]
|
||||||
if len(nodes) == 1:
|
if len(nodes) == 1:
|
||||||
config[key] = override_value
|
tree[key] = override_value
|
||||||
else:
|
else:
|
||||||
next_key = nodes[1:]
|
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):
|
def _get_config_node(config: dict, key: str):
|
||||||
|
|
Loading…
Add table
Reference in a new issue