fix(cli): allow parent options after subcommand arguments #6000
+125
−2
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
Follow-up to #5983. Extends parent option parsing to work across subcommand boundaries.
Enables parent/global options to appear anywhere in the command line, including after subcommand names and their arguments. This follows the common CLI pattern used by git, npm, docker, and most modern CLI tools.
Before
After
Motivation: The Centralized Flags Pattern
Many CLI applications define global options on the parent command that affect all subcommands:
Users naturally expect to place these global options at the end of their command:
This change removes that friction by extracting known parent options from anywhere in the args.
Implementation
getParentOptionNames()- Collects all option names (including aliases) from a parent commandextractParentOptionsFromArgs()- Scans args after the subcommand for known parent options and extracts themSubcommandscase inparseInternalto use these helpers before splitting argsUses
Setfor O(1) lookups on both subcommand names and parent option names.Test Plan
--option=valueformat🤖 Generated with Claude Code