Skip to content

Commit

Permalink
Merge pull request #224 from bogdant36/CTX-5889-fix-v1
Browse files Browse the repository at this point in the history
CTX-5921: Added new condition in onBeforeCommandExecute() callback wh…
  • Loading branch information
dule1322 committed Jul 1, 2024
2 parents 2260321 + 743c8aa commit 8fe02cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coretex/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def update() -> None:


@click.group(cls = ClickExceptionInterceptor)
@utils.onBeforeCommandExecute(utils.checkLibVersion)
@utils.onBeforeCommandExecute(utils.checkLibVersion, excludeSubcommands = ["update"])
def cli() -> None:
pass

Expand Down
13 changes: 12 additions & 1 deletion coretex/cli/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,24 @@ 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 excludeSubcommands:
return f(*args, **kwargs)

for key, value in click.get_current_context().params.items():
if key in excludeOptions and value:
return f(*args, **kwargs)
Expand Down

0 comments on commit 8fe02cb

Please sign in to comment.