From 6511a11f7060e699fb7eba3ce8b8a91d789536e0 Mon Sep 17 00:00:00 2001 From: Bogdan Tintor Date: Fri, 28 Jun 2024 13:27:26 +0200 Subject: [PATCH 1/3] CTX-5921: Added new condition in onBeforeCommandExecute() callback which will check if "command_name" is inside excludeOptions also. --- coretex/cli/main.py | 2 +- coretex/cli/modules/utils.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/coretex/cli/main.py b/coretex/cli/main.py index 296fc1b4..56512e5c 100644 --- a/coretex/cli/main.py +++ b/coretex/cli/main.py @@ -61,7 +61,7 @@ def update() -> None: @click.group(cls = ClickExceptionInterceptor) -@utils.onBeforeCommandExecute(utils.checkLibVersion) +@utils.onBeforeCommandExecute(utils.checkLibVersion, excludeOptions = ["update"]) def cli() -> None: pass diff --git a/coretex/cli/modules/utils.py b/coretex/cli/modules/utils.py index 4894be3b..986fc7f9 100644 --- a/coretex/cli/modules/utils.py +++ b/coretex/cli/modules/utils.py @@ -157,6 +157,9 @@ def onBeforeCommandExecute(fun: Callable[..., Any], excludeOptions: Optional[Lis def decorator(f: Callable[..., Any]) -> Callable[..., Any]: @wraps(f) def wrapper(*args: Any, **kwargs: Any) -> Any: + if click.get_current_context().invoked_subcommand in excludeOptions: + return f(*args, **kwargs) + for key, value in click.get_current_context().params.items(): if key in excludeOptions and value: return f(*args, **kwargs) From 38f2215f9be8e191ceca494fa9b7bce90210d023 Mon Sep 17 00:00:00 2001 From: Bogdan Tintor Date: Mon, 1 Jul 2024 09:31:25 +0200 Subject: [PATCH 2/3] CTX-5921: Discussion changes. --- coretex/cli/modules/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/coretex/cli/modules/utils.py b/coretex/cli/modules/utils.py index 986fc7f9..ab9d0385 100644 --- a/coretex/cli/modules/utils.py +++ b/coretex/cli/modules/utils.py @@ -150,14 +150,22 @@ def isGPUAvailable() -> bool: return False -def onBeforeCommandExecute(fun: Callable[..., Any], excludeOptions: Optional[List[str]] = None) -> Any: +def onBeforeCommandExecute( + fun: Callable[..., Any], + excludeOptions: Optional[List[str]] = None, + excludeSubcommands: Optional[List[str]] = None +) -> Any: + if excludeOptions is None: excludeOptions = [] + if excludeSubcommands is None: + excludeSubcommands = [] + def decorator(f: Callable[..., Any]) -> Callable[..., Any]: @wraps(f) def wrapper(*args: Any, **kwargs: Any) -> Any: - if click.get_current_context().invoked_subcommand in excludeOptions: + if click.get_current_context().invoked_subcommand in excludeSubcommands: return f(*args, **kwargs) for key, value in click.get_current_context().params.items(): From 743c8aa277a4fc51adb14b65e5946914f892c251 Mon Sep 17 00:00:00 2001 From: Bogdan Tintor Date: Mon, 1 Jul 2024 11:04:38 +0200 Subject: [PATCH 3/3] CTX-5921: leftover commit --- coretex/cli/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coretex/cli/main.py b/coretex/cli/main.py index 56512e5c..92151481 100644 --- a/coretex/cli/main.py +++ b/coretex/cli/main.py @@ -61,7 +61,7 @@ def update() -> None: @click.group(cls = ClickExceptionInterceptor) -@utils.onBeforeCommandExecute(utils.checkLibVersion, excludeOptions = ["update"]) +@utils.onBeforeCommandExecute(utils.checkLibVersion, excludeSubcommands = ["update"]) def cli() -> None: pass