Fix OptionGroup type names appearing in help usage string#873
Merged
natecook1000 merged 4 commits intoMar 19, 2026
Conversation
When all arguments are optional and an @OptionGroup's type conforms to ParsableCommand, the help flag's usage string incorrectly prepends the OptionGroup type name to the command stack (e.g., 'USAGE: option-group-options test ...' instead of 'USAGE: test ...'). This happens because the commandStack property on CommandParser includes all decoded ParsableCommand types, including those decoded as @OptionGroup members rather than actual commands in the command tree. Fix: Filter commandStack to only include types that exist as nodes in the command tree, excluding @OptionGroup types that happen to conform to ParsableCommand.
Collaborator
|
Wild and great catch! @natecook1000 the behavior change here is 100% correct and I think the implementation makes sense too. could you do a quick review too |
natecook1000
left a comment
Member
There was a problem hiding this comment.
Thanks @william-laverty – LGTM! Could you fix the formatting issue and we'll get this merged?
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
@natecook1000 @rauhul Fixed the formatting issue, lmk if there's anything else. p.s. probably didn't need to use Opus for that commit but oh well, hope the tokens are worth it :) |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
natecook1000
approved these changes
Mar 19, 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.
Summary
Fixes #578.
When all arguments are optional and an
@OptionGroup's type conforms toParsableCommand, the--helpflag's usage string incorrectly prepends the OptionGroup type name to the command stack.Before:
After:
Root Cause
The
commandStackcomputed property onCommandParserincludes all decoded types that conform toParsableCommand, including those decoded as@OptionGroupmembers. When all arguments have default values, the parser successfully decodes the command (including its OptionGroup), and the OptionGroup'sParsableCommandtype leaks intocommandStackbefore the--helpflag is caught.Fix
Filter
commandStackto only include types that exist as actual nodes in the command tree (commandTree), excluding@OptionGrouptypes that happen to conform toParsableCommand.Test
Added a regression test in
HelpGenerationTeststhat usesparseAsRoot(["--help"])to verify the usage string from the built-in help flag does not include the OptionGroup type name.