-
-
Notifications
You must be signed in to change notification settings - Fork 518
test/docs(cli): document and test parent options after subcommand arguments #6000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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
|
@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>
…r section Show actual @effect/cli code for flexible option placement and shared option resolution instead of referencing git behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The extractParentOptionsFromArgs mechanism and all supporting helpers (getParentOptionInfo, collectBooleanNames, getChildOptionNames) are redundant — PR Effect-TS#5983's parseCommandLine scan + child leftover re-parse path already handles parent options after subcommand args, including shared option resolution and boolean awareness. 177/177 tests pass without any of this code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests the pattern where a parent command provides shared options (like --verbose) as a service to subcommands. Verifies parent options work when placed after subcommand names and subcommand options. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
ok @IMax153 sorry about that - the original PR actually already fixed all issues. I had a stale lockfile that wasn't resolving to .1 in a project - leading me to believe the fix wasn't complete. This PR now updates documentation and adds more tests to reflect current behaviour |
Summary
Follow-up to #5983. Adds tests and documentation for parent options appearing after subcommand arguments — a behavior #5983 already enabled via the
parseCommandLinescan and child-leftover re-parse path.=syntax, short aliases, and theprovideSyncservice pattern@effect/clicode examples, and corrected the FAQ which previously stated options must precede subcommands/argsextractParentOptionsFromArgsextraction layer (and all supporting helpers) that duplicated what fix(cli): allow options after positional arguments #5983's re-parse path already handles — zero source diff oncommandDescriptor.tsKey behaviors documented and tested
app push --force --verbose— parent--verboseafter subcommand optionapp show main --verbose— parent--verboseafter subcommand positional argapp --verbose push --force— parent--verbosebefore subcommand (existing)tool exec task --verbose— shared option goes to child when after subcommandtool --verbose exec task— shared option goes to parent when before subcommandTest plan
pnpm --filter @effect/cli test— 182/182 passpnpm --filter @effect/cli check— cleanReceived unknown argument)🤖 Generated with Claude Code