Skip to content
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

Restore arguments order to pass to subcommands #734

Closed
wants to merge 1 commit into from

Conversation

maxlath
Copy link

@maxlath maxlath commented Dec 16, 2017

so that option parsing is done by the subcommand, which may have its own options.

Addressed cases of the kind: cmd subcmd -o arg1 arg2 where -o is a boolean option defined on the subcommand, and thus will not be identified by parseOptions when called from the parent command, and fall in the // looks like an option block, which will alter the arguments order: the subcommand will receive an args array that looks like [ arg2, -o, arg1 ]

Possibly related to #692 and #289

maxlath added a commit to maxlath/wikibase-cli that referenced this pull request Dec 16, 2017
maxlath added a commit to maxlath/wikibase-cli that referenced this pull request Dec 16, 2017
so that option parsing is done by the subcommand, which may have its own options.
Addressed case:
`cmd subcmd -o arg1 arg2` where `-o` is defined on the subcommand
was passing an args array like `[ arg2, -o, arg1 ]` to the subcommand
@shadowspawn
Copy link
Collaborator

I think we need some better details about expected pattern for git-style commands! I need to do some experimentation to better understand before reviewing this PR.

(I am surprised things are potentially this broken, which makes me wonder if there are some calling patterns which are ok.)

@shadowspawn shadowspawn self-requested a review May 13, 2019 09:32
@shadowspawn shadowspawn added this to the v3.0.0 milestone Jun 22, 2019
@shadowspawn
Copy link
Collaborator

This is being considered for v3 (since it seems a nasty bug!), but has not passed any reviews yet, and won't be merged until approved. I am willing to help with code changes if needed.

@shadowspawn
Copy link
Collaborator

Another possibly related issue: #508
And noting that #962 has some analysis.

@shadowspawn
Copy link
Collaborator

shadowspawn commented Jun 27, 2019

There is a bug but it is unfortunately harder and more subtle to fix than this. The top level command can have options which are currently removed before calling the sub command. This may not be common, but it would dramatically change the behaviour to pass the original args through to the sub-command. e.g.

node index.js --debug hello 1 2 --dry-run 3 4 5 6 

Thank you for your contributions.

@shadowspawn shadowspawn removed this from the v3.0.0 milestone Jul 1, 2019
@maxlath
Copy link
Author

maxlath commented Oct 4, 2019

hi! sorry for the slow reaction, I made a test repo to demonstrate the issue: https://github.com/maxlath/commander-subcommand-argument-order-demo

@shadowspawn
Copy link
Collaborator

Thanks @maxlath. I think this is the same issue as in #508 and #962 (and is a bug).

@shadowspawn
Copy link
Collaborator

The parsing got a major shakeup and argument order is now preserved in the published pre-release of Commander v5.0.0 (#1163)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants