Preserve option terminator in subcommand arguments for subcommand to process - #2577
Open
shadowspawn wants to merge 4 commits into
Open
Preserve option terminator in subcommand arguments for subcommand to process#2577shadowspawn wants to merge 4 commits into
shadowspawn wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
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
parseOptionsto retain--and remaining args asunknownwhen 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.
shadowspawn
marked this pull request as ready for review
August 6, 2026 23:48
Repository owner
deleted a comment from
HyphensPeciwse33
Sep 1, 2026
Repository owner
deleted a comment from
HyphensPeciwse33
Sep 1, 2026
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.
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