From ca8e9f85e4fd0fe9b6c43c2b27d4cfae1b9cbe14 Mon Sep 17 00:00:00 2001 From: sriniv27 Date: Wed, 17 Feb 2021 07:46:22 -0500 Subject: [PATCH] forward override unpacking to yaml library --- jrnl/args.py | 21 +++++++-------------- tests/test_parse_args.py | 6 +++--- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/jrnl/args.py b/jrnl/args.py index 111e41e6..0d635afd 100644 --- a/jrnl/args.py +++ b/jrnl/args.py @@ -4,6 +4,8 @@ import argparse import re import textwrap +import yaml +from yaml.loader import FullLoader from .commands import postconfig_decrypt from .commands import postconfig_encrypt @@ -16,6 +18,8 @@ from .plugins import EXPORT_FORMATS from .plugins import IMPORT_FORMATS from .plugins import util +YAML_SEPARATOR = ": " + def deserialize_config_args(input: list) -> dict: @@ -30,21 +34,10 @@ def deserialize_config_args(input: list) -> dict: """ assert len(input) == 2 - runtime_modifications = {} - 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 + # yaml compatible strings are of the form Key:Value + yamlstr = YAML_SEPARATOR.join(input) + runtime_modifications = yaml.load(yamlstr, Loader=FullLoader) return runtime_modifications diff --git a/tests/test_parse_args.py b/tests/test_parse_args.py index feb31d07..2ce0b6a9 100644 --- a/tests/test_parse_args.py +++ b/tests/test_parse_args.py @@ -266,7 +266,7 @@ class TestDeserialization: @pytest.mark.parametrize( "input_str", [ - ["editor", '"nano"'], + ["editor", "nano"], ["colors.title", "blue"], ["default", "/tmp/egg.txt"], ], @@ -285,8 +285,8 @@ class TestDeserialization: cfg = deserialize_config_args(["encrypt", "false"]) assert cfg["encrypt"] == False - cfg = deserialize_config_args(["editor", '"vi -c startinsert"']) - assert cfg["editor"] == '"vi -c startinsert"' + cfg = deserialize_config_args(["editor", "vi -c startinsert"]) + assert cfg["editor"] == "vi -c startinsert" cfg = deserialize_config_args(["highlight", "true"]) assert cfg["highlight"] == True