From 84bedd7dc7ab4625a77fac9fae399aab316d3a05 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Mon, 8 Jan 2024 18:09:59 +0100 Subject: [PATCH] Fixed issues with remove and clean commands when build key is missing Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/commands.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cfbs/commands.py b/cfbs/commands.py index 2fe05548..cd529727 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -392,6 +392,10 @@ def add_command( def remove_command(to_remove: list): config = CFBSConfig.get_instance() config.warn_about_unknown_keys() + if not "build" in config: + user_error( + 'Cannot remove any modules because the "build" key is missing from cfbs.json' + ) modules = config["build"] def _get_module_by_name(name) -> dict: @@ -478,7 +482,12 @@ def _clean_unused_modules(config=None): if not config: config = CFBSConfig.get_instance() config.warn_about_unknown_keys() + if "build" not in config: + log.warning('No "build" key with modules - nothing to clean') + return 0 modules = config["build"] + if len(modules) == 0: + return 0 def _someone_needs_me(this) -> bool: if "added_by" not in this or this["added_by"] == "cfbs add":