mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
forward override unpacking to yaml library
This commit is contained in:
parent
bd0394c124
commit
ca8e9f85e4
2 changed files with 10 additions and 17 deletions
21
jrnl/args.py
21
jrnl/args.py
|
@ -4,6 +4,8 @@
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import yaml
|
||||||
|
from yaml.loader import FullLoader
|
||||||
|
|
||||||
from .commands import postconfig_decrypt
|
from .commands import postconfig_decrypt
|
||||||
from .commands import postconfig_encrypt
|
from .commands import postconfig_encrypt
|
||||||
|
@ -16,6 +18,8 @@ from .plugins import EXPORT_FORMATS
|
||||||
from .plugins import IMPORT_FORMATS
|
from .plugins import IMPORT_FORMATS
|
||||||
from .plugins import util
|
from .plugins import util
|
||||||
|
|
||||||
|
YAML_SEPARATOR = ": "
|
||||||
|
|
||||||
|
|
||||||
def deserialize_config_args(input: list) -> dict:
|
def deserialize_config_args(input: list) -> dict:
|
||||||
|
|
||||||
|
@ -30,21 +34,10 @@ def deserialize_config_args(input: list) -> dict:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert len(input) == 2
|
assert len(input) == 2
|
||||||
runtime_modifications = {}
|
|
||||||
|
|
||||||
cfg_key = input[0]
|
# yaml compatible strings are of the form Key:Value
|
||||||
cfg_value = input[1]
|
yamlstr = YAML_SEPARATOR.join(input)
|
||||||
cfg_value = cfg_value.strip()
|
runtime_modifications = yaml.load(yamlstr, Loader=FullLoader)
|
||||||
|
|
||||||
# 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
|
return runtime_modifications
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ class TestDeserialization:
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"input_str",
|
"input_str",
|
||||||
[
|
[
|
||||||
["editor", '"nano"'],
|
["editor", "nano"],
|
||||||
["colors.title", "blue"],
|
["colors.title", "blue"],
|
||||||
["default", "/tmp/egg.txt"],
|
["default", "/tmp/egg.txt"],
|
||||||
],
|
],
|
||||||
|
@ -285,8 +285,8 @@ class TestDeserialization:
|
||||||
cfg = deserialize_config_args(["encrypt", "false"])
|
cfg = deserialize_config_args(["encrypt", "false"])
|
||||||
assert cfg["encrypt"] == False
|
assert cfg["encrypt"] == False
|
||||||
|
|
||||||
cfg = deserialize_config_args(["editor", '"vi -c startinsert"'])
|
cfg = deserialize_config_args(["editor", "vi -c startinsert"])
|
||||||
assert cfg["editor"] == '"vi -c startinsert"'
|
assert cfg["editor"] == "vi -c startinsert"
|
||||||
|
|
||||||
cfg = deserialize_config_args(["highlight", "true"])
|
cfg = deserialize_config_args(["highlight", "true"])
|
||||||
assert cfg["highlight"] == True
|
assert cfg["highlight"] == True
|
||||||
|
|
Loading…
Add table
Reference in a new issue