forward override unpacking to yaml library

This commit is contained in:
sriniv27 2021-02-17 07:46:22 -05:00
parent bd0394c124
commit ca8e9f85e4
2 changed files with 10 additions and 17 deletions

View file

@ -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

View file

@ -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