Skip to content

Conversation

@cevr
Copy link
Contributor

@cevr cevr commented Jan 26, 2026

Summary

Follow-up to #5983. Adds tests and documentation for parent options appearing after subcommand arguments — a behavior #5983 already enabled via the parseCommandLine scan and child-leftover re-parse path.

  • Tests: 30+ new tests covering parent options after subcommand args, shared option resolution (child wins), boolean options, = syntax, short aliases, and the provideSync service pattern
  • Docs: Updated README to reflect flexible option placement with concrete @effect/cli code examples, and corrected the FAQ which previously stated options must precede subcommands/args
  • Cleanup: Removed redundant extractParentOptionsFromArgs extraction 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 on commandDescriptor.ts

Key behaviors documented and tested

  • app push --force --verbose — parent --verbose after subcommand option
  • app show main --verbose — parent --verbose after subcommand positional arg
  • app --verbose push --force — parent --verbose before subcommand (existing)
  • tool exec task --verbose — shared option goes to child when after subcommand
  • tool --verbose exec task — shared option goes to parent when before subcommand

Test plan

🤖 Generated with Claude Code

@cevr cevr requested a review from IMax153 as a code owner January 26, 2026 03:20
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Jan 26, 2026
@changeset-bot
Copy link

changeset-bot bot commented Jan 26, 2026

⚠️ No Changeset found

Latest commit: a6f117e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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>
@cevr cevr force-pushed the fix/cli-parent-options-after-subcommand branch from ad5704b to c8c5f43 Compare January 26, 2026 03:22
@IMax153
Copy link
Member

IMax153 commented Feb 6, 2026

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

cevr and others added 5 commits February 6, 2026 13:04
…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>
@cevr
Copy link
Contributor Author

cevr commented Feb 6, 2026

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

@cevr cevr changed the title fix(cli): allow parent options after subcommand arguments test/docs(cli): document and test parent options after subcommand arguments Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

2 participants