Skip to content

Preserve option terminator in subcommand arguments for subcommand to process - #2577

Open
shadowspawn wants to merge 4 commits into
tj:release/16.xfrom
shadowspawn:pass-option-delimiter-into-subcommand
Open

Preserve option terminator in subcommand arguments for subcommand to process#2577
shadowspawn wants to merge 4 commits into
tj:release/16.xfrom
shadowspawn:pass-option-delimiter-into-subcommand

Conversation

@shadowspawn

@shadowspawn shadowspawn commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Problem

The option delimiter is stripped during top level pass of arguments by root command before the subcommand sees the arguments. This works for internal subcommands (action handler) because the following arguments are marked as having been processed. This does not work for external subcommands which just get the arguments without the option terminator and following options get processed as normal.

Issue: #2530

Solution

Leave the option terminator and the remaining arguments as "unknown" for the subcommand to reprocess. This works for both internal and external commands.

The option terminator tests were weak. Beefed them up to cover the external case and more besides.

This is a change in core behaviour, so marking PR as semver-major.

ChangeLog

@shadowspawn shadowspawn added the semver: major Releasing requires a major version bump, not backwards compatible label Aug 5, 2026
@shadowspawn
shadowspawn requested a lite review from Copilot August 6, 2026 23:42
@shadowspawn shadowspawn changed the title Preserve option delimiter in subcommand arguments for subcommand to process Preserve option terminator in subcommand arguments for subcommand to process Aug 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes Commander’s option-terminator (--) handling so that when the parent command is dispatching to a subcommand (including executable subcommands), the delimiter and remaining arguments are preserved for the subcommand to reprocess—fixing the external-subcommand case described in #2530.

Changes:

  • Update parseOptions to retain -- and remaining args as unknown when the first operand is a known subcommand, so dispatch passes them through unchanged (including to executable subcommands).
  • Expand and strengthen tests around -- handling across top-level parsing, in-process subcommands, default commands, and executable subcommands.
  • Refactor the delimiter tests to use a shared helper for consistent option setup.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/command.js Preserves -- for subcommand dispatch by moving the delimiter and remaining args into unknown when a subcommand is detected.
tests/args.literal.test.js Adds broader coverage for delimiter behavior, including executable subcommand pass-through and multiple edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/args.literal.test.js Outdated
@shadowspawn
shadowspawn marked this pull request as ready for review August 6, 2026 23:48
@shadowspawn
shadowspawn changed the base branch from develop to release/16.x August 6, 2026 23:50
Repository owner deleted a comment from HyphensPeciwse33 Sep 1, 2026
Repository owner deleted a comment from HyphensPeciwse33 Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver: major Releasing requires a major version bump, not backwards compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants