fix(parser): exclude hidden subcommands from suggestions#6302
Draft
Stefan-H-H wants to merge 2 commits intoclap-rs:masterfrom
Draft
fix(parser): exclude hidden subcommands from suggestions#6302Stefan-H-H wants to merge 2 commits intoclap-rs:masterfrom
Stefan-H-H wants to merge 2 commits intoclap-rs:masterfrom
Conversation
added 2 commits
March 10, 2026 17:11
Hidden subcommands marked with .hide(true) were still appearing in 'did you mean' suggestions when users typed similar unrecognized commands. This change filters out hidden subcommands in all_subcommand_names() to maintain consistency with help text behavior where hidden commands are not displayed. The function is only used in two places: 1. Parser - for generating 'did you mean' suggestions 2. Validator - for listing available subcommands in error messages Both are user-facing error messages where hidden commands should not appear. Fixes the issue where hidden commands would be suggested despite being intentionally hidden from users.
Member
|
We ask in our contrib guide for problems and solutions to be determined in an issue before moving on to a PR. An issue for this already exists at #4853. Moving to a draft to focus the attention over there. |
scutuatua-crypto
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes an issue where hidden subcommands (marked with
.hide(true)) were still appearing in "did you mean" suggestions when users typed similar unrecognized commands.Problem
When a subcommand is explicitly hidden using
.hide(true), it correctly doesn't appear in help text. However, when a user types an unrecognized command similar to the hidden subcommand, clap would still suggest it in the error message.Solution
Modified
all_subcommand_names()inclap_builder/src/builder/command.rsto filter out hidden subcommands. This maintains consistency with help text behavior where hidden commands are not displayed.The function is only used in two places:
Both are user-facing error messages where hidden commands should not appear.
Testing
subcmd_did_you_mean_hidden_not_suggested