Skip to content

fix help hint showing shadowed option name#3208

Merged
Rowlando13 merged 3 commits into
pallets:mainfrom
Mr-Neutr0n:fix/help-option-shadowing-suggestion
Apr 29, 2026
Merged

fix help hint showing shadowed option name#3208
Rowlando13 merged 3 commits into
pallets:mainfrom
Mr-Neutr0n:fix/help-option-shadowing-suggestion

Conversation

@Mr-Neutr0n

Copy link
Copy Markdown
Contributor

Fixes #2790.

When a subcommand defines an option that shadows one of the configured help option names (e.g. -h), the error hint was still suggesting the shadowed name:

Try 'cli foo -h' for help.

But -h is now the subcommand's --host option, not help. Running cli foo -h gives Error: Option '-h' requires an argument. instead of showing help.

The fix uses get_help_option_names() which already exists and filters out names claimed by other parameters. So now the hint picks a working alternative like --help:

Try 'cli foo --help' for help.

@kdeldycke kdeldycke changed the base branch from main to stable April 16, 2026 09:34
@kdeldycke kdeldycke added this to the 8.4.0 milestone Apr 21, 2026
@kdeldycke kdeldycke force-pushed the fix/help-option-shadowing-suggestion branch from b981ca9 to 10841e5 Compare April 21, 2026 15:57
@kdeldycke

Copy link
Copy Markdown
Collaborator

I just reworked that PR to be more resilient against various cases of default option names overriding. Also added unittests to illustrate all these edge-cases.

@kdeldycke kdeldycke added bug f:help feature: help text labels Apr 21, 2026
Fix pallets#2790.

Co-authored-by: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com>
@kdeldycke kdeldycke force-pushed the fix/help-option-shadowing-suggestion branch from 10841e5 to 1241aba Compare April 21, 2026 16:03
@Rowlando13 Rowlando13 changed the base branch from stable to main April 29, 2026 06:57
@Rowlando13 Rowlando13 merged commit 0cd28d6 into pallets:main Apr 29, 2026
12 checks passed
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug f:help feature: help text

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested command option shadowing -h prints wrong suggestion

3 participants