Skip to content

fix(parser): exclude hidden subcommands from suggestions#6302

Draft
Stefan-H-H wants to merge 2 commits intoclap-rs:masterfrom
Stefan-H-H:fix/hidden-subcommand-suggestions
Draft

fix(parser): exclude hidden subcommands from suggestions#6302
Stefan-H-H wants to merge 2 commits intoclap-rs:masterfrom
Stefan-H-H:fix/hidden-subcommand-suggestions

Conversation

@Stefan-H-H
Copy link
Copy Markdown

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() in clap_builder/src/builder/command.rs to 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:

  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.

Testing

  • Added new test case subcmd_did_you_mean_hidden_not_suggested
  • All existing tests pass (138 subcommand-related tests)
  • Verified hidden commands can still be invoked directly (only suggestions are affected)

Stefan Hristov 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.
@epage
Copy link
Copy Markdown
Member

epage commented Mar 11, 2026

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.

@epage epage marked this pull request as draft March 11, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants