fix(cli): allow parent options after subcommand arguments#6000
Open
cevr wants to merge 1 commit intoEffect-TS:mainfrom
Open
fix(cli): allow parent options after subcommand arguments#6000cevr wants to merge 1 commit intoEffect-TS:mainfrom
cevr wants to merge 1 commit intoEffect-TS:mainfrom
Conversation
|
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: cli --global-opt subcommand arg # works cli subcommand arg --global-opt # fails: "unknown option" After: cli --global-opt subcommand arg # works cli subcommand arg --global-opt # works This is useful for the "centralized flags" pattern where global options like --verbose, --config, or --model are defined on the parent command and inherited by all subcommands. Users can now place these options at the end of the command for better ergonomics. Implementation: - Extract parent option names before splitting args at subcommand boundary - Scan args after subcommand for known parent options - Pass extracted parent options to parent command parsing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ad5704b to
c8c5f43
Compare
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
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