From 901cb664c64b53c673eaf0d0fec97da5de52152d Mon Sep 17 00:00:00 2001 From: Jakub Frejlach Date: Mon, 27 Nov 2023 16:29:41 +0100 Subject: [PATCH] Fix custom command check on tab completion Check for mutually exclusive groups or one of groups should only run when griffon itself is running. During tab completion these checks should be disabled. --- CHANGELOG.md | 2 ++ griffon/commands/custom_commands.py | 49 +++++++++++++++-------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dedcc6..677b592 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed * standardized progress bar accross whole Griffon which fixes no_progress_bar functionality +* fixed tab autocompletion for mutually exclusive and one of + option/argument groups ## [0.3.8] - 2023-10-18 ### Added diff --git a/griffon/commands/custom_commands.py b/griffon/commands/custom_commands.py index d21b8bc..41a465c 100644 --- a/griffon/commands/custom_commands.py +++ b/griffon/commands/custom_commands.py @@ -27,30 +27,33 @@ class BaseGroupParameter: """ def handle_parse_result(self, ctx, opts, args): - if self.mutually_exclusive_group: - if opts.get(self.name) is None: - pass # skip check for not supplied click.Arguments - elif self.name in opts and any( - opt in opts for opt in self.mutually_exclusive_group if opts.get(opt) is not None - ): - raise GriffonUsageError( - ( - f"{Style.BOLD}{self.name} cannot be used with " - f"{', '.join(self.mutually_exclusive_group)}.{Style.RESET}" - ), - ctx=ctx, - ) - - if self.required_group: - group_set = set( - opt for opt in opts if opt in self.required_group and opts.get(opt) is not None - ) - if not any(group_set): - raise GriffonUsageError( - f"{Style.BOLD}At least one of {', '.join(self.required_group)} " - f"is required.{Style.RESET}", - ctx=ctx, + if not ctx.resilient_parsing: + if self.mutually_exclusive_group: + if opts.get(self.name) is None: + pass # skip check for not supplied click.Arguments + elif self.name in opts and any( + opt in opts + for opt in self.mutually_exclusive_group + if opts.get(opt) is not None + ): + raise GriffonUsageError( + ( + f"{Style.BOLD}{self.name} cannot be used with " + f"{', '.join(self.mutually_exclusive_group)}.{Style.RESET}" + ), + ctx=ctx, + ) + + if self.required_group: + group_set = set( + opt for opt in opts if opt in self.required_group and opts.get(opt) is not None ) + if not any(group_set): + raise GriffonUsageError( + f"{Style.BOLD}At least one of {', '.join(self.required_group)} " + f"is required.{Style.RESET}", + ctx=ctx, + ) return super().handle_parse_result(ctx, opts, args)