From 1fa3ba61c8835d4ab2a804fd933b1744144cbcf9 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Tue, 7 Feb 2023 20:44:34 +0000 Subject: [PATCH] Fix crash when using cfg on empty/new configs Fixes #19. --- devine/commands/cfg.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/devine/commands/cfg.py b/devine/commands/cfg.py index 7ac56f6..a02f91a 100644 --- a/devine/commands/cfg.py +++ b/devine/commands/cfg.py @@ -45,6 +45,10 @@ def cfg(ctx: click.Context, key: str, value: str, unset: bool, list_: bool) -> N if not data: log.warning(f"{config_path} has no configuration data, yet") + # yaml.load() returns `None` if the input data is blank instead of a usable object + # force a usable object by making one and removing the only item within it + data = yaml.load("""__TEMP__: null""") + del data["__TEMP__"] if list_: yaml.dump(data, sys.stdout)