Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Fix custom command check on tab completion
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JakubFrejlach committed Dec 5, 2023
1 parent 11ace7a commit 7d2dc79
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 26 additions & 23 deletions griffon/commands/custom_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 7d2dc79

Please sign in to comment.