Incorrectly guessed parameters to boolean options should be arguments to a command. #75
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.
To illustrate the issue, consider the simple command below that prints the string it is given. Call this file cmd.js:
When run without any options, it works fine. The problem arises when the
-e
or--example
boolean option is provided before the input<str>
, like so:Even though
-e
is a boolean option, "hello" is guessed to be its argument in thelib/commander.js
on line 504:The "hello" argument is then ignored, which makes the command fail.
I have fixed this issue in the latest commit below by reinserting incorrectly guessed option parameters back into the arguments array for a command. Let me know if you have any questions about the code and if there any changes I need to make.
I also noticed that the date test in
test.prompt.js
was failing. It seems to be that this line:was acting up even though
actual
was indeed an instance ofDate
. In fact, I changed it to:and it still failed. As a result, I modified the test to use
should.equal(true)
instead, like so:and it passed.
Update: I've omitted the test fix above to make this pull request focus on just one issue. Let me know if you'd like another pull request for the tests; it's just a minor bug anyway.
I've been using commander.js for one of my personal projects and have been pleased with its robustness. I'd love to fix these issues and give back. Don't hesitate if you have any questions or need me to modify something.