From 3862ea190197304cac4c6f5a71322a3888b15a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Wed, 19 Jan 2022 15:35:33 +0100 Subject: [PATCH] get_command member find method --- kiwi_scp/commands/cli.py | 11 +++++++++-- kiwi_scp/commands/cmd_enable.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kiwi_scp/commands/cli.py b/kiwi_scp/commands/cli.py index f38b72e..88812d3 100644 --- a/kiwi_scp/commands/cli.py +++ b/kiwi_scp/commands/cli.py @@ -26,9 +26,16 @@ class KiwiCLI(click.MultiCommand): except ImportError: return - for cmd_name in dir(cmd_module): - member = getattr(cmd_module, cmd_name) + member_name = f"{cmd_name.capitalize()}Command" + + if member_name in dir(cmd_module): + member = getattr(cmd_module, member_name) + if isinstance(member, click.Command): return member + else: + raise Exception("Fail class") + else: + raise Exception("Fail member name") diff --git a/kiwi_scp/commands/cmd_enable.py b/kiwi_scp/commands/cmd_enable.py index 54d89be..def3017 100644 --- a/kiwi_scp/commands/cmd_enable.py +++ b/kiwi_scp/commands/cmd_enable.py @@ -13,7 +13,7 @@ from ..project import Project help=f"skip confirmation", ) @kiwi_command() -class DisableCommand(KiwiCommand): +class EnableCommand(KiwiCommand): """Enable project(s)""" type = KiwiCommandType.PROJECTS