fix(cli): allow parent options after subcommand arguments#6000
Open
cevr wants to merge 3 commits intoEffect-TS:mainfrom
Open
fix(cli): allow parent options after subcommand arguments#6000cevr wants to merge 3 commits intoEffect-TS:mainfrom
cevr wants to merge 3 commits intoEffect-TS:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 9d14d28 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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
Member
|
@cevr - I don't think the PR can be accepted in it's current form. We would need to document the precise behavior of what occurs when a parent command and subcommand share a common option. We would also need to document that that this behavior is only valid for options (not arguments). In addition, we would need several more tests to ensure the implemented behavior is what we expect. |
…on extraction Child wins for shared options after subcommand (matches CLI conventions). Boolean parent options no longer steal the next token as a value. Adds comprehensive descriptor-level and integration tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ions The FAQ and usage sections incorrectly stated options must appear before positional args and subcommands. Updated to reflect the new behavior and document shared option resolution (child wins after subcommand). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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