Skip to content

Fix OptionGroup type names appearing in help usage string#873

Merged
natecook1000 merged 4 commits into
apple:mainfrom
william-laverty:fix-option-group-usage-string
Mar 19, 2026
Merged

Fix OptionGroup type names appearing in help usage string#873
natecook1000 merged 4 commits into
apple:mainfrom
william-laverty:fix-option-group-usage-string

Conversation

@william-laverty

Copy link
Copy Markdown
Contributor

Summary

Fixes #578.

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.

Before:

USAGE: option-group-options test [--num <num>] [<arg>]

After:

USAGE: test [--num <num>] [<arg>]

Root Cause

The commandStack computed property on CommandParser includes all decoded types that conform to ParsableCommand, including those decoded as @OptionGroup members. When all arguments have default values, the parser successfully decodes the command (including its OptionGroup), and the OptionGroup's ParsableCommand type leaks into commandStack before the --help flag is caught.

Fix

Filter commandStack to only include types that exist as actual nodes in the command tree (commandTree), excluding @OptionGroup types that happen to conform to ParsableCommand.

Test

Added a regression test in HelpGenerationTests that uses parseAsRoot(["--help"]) to verify the usage string from the built-in help flag does not include the OptionGroup type name.

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.
@rauhul

rauhul commented Mar 10, 2026

Copy link
Copy Markdown
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 natecook1000 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@william-laverty

william-laverty commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @william-laverty – LGTM! Could you fix the formatting issue and we'll get this merged?

@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 :)

@william-laverty william-laverty marked this pull request as draft March 16, 2026 01:52
@william-laverty william-laverty marked this pull request as ready for review March 16, 2026 01:52
@william-laverty william-laverty marked this pull request as draft March 16, 2026 01:53
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@william-laverty william-laverty marked this pull request as ready for review March 16, 2026 03:05
@natecook1000 natecook1000 merged commit 650976f into apple:main Mar 19, 2026
35 checks passed
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.

Usage generated by built-in help flag prepends names of OptionGroups to command stack if all arguments are optional

3 participants