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

allow "-" hyphen as an option argument with subcommand #697

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -737,7 +737,7 @@ Command.prototype.parseOptions = function(argv) {
// If the next argument looks like it might be
// an argument for this option, we pass it on.
// If it isn't, then it'll simply be ignored
if (argv[i+1] && '-' != argv[i+1][0]) {
if (argv[i+1] && ('-' != argv[i+1][0] || '-' === argv[i+1])) {
unknownOptions.push(argv[++i]);
}
continue;
Expand Down
21 changes: 21 additions & 0 deletions test/test.options.subcommand-hyphen.js
@@ -0,0 +1,21 @@
/**
* Module dependencies.
*/

var program = require('../')
, should = require('should');

program
.command('subcommand')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please set the indent width to 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abetomo I fixed it. Thank you for your review!

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

.description('description')
.option('-a, --alpha <a>', 'hyphen')
.option('-b, --bravo <b>', 'hyphen')
.option('-c, --charlie <c>', 'hyphen')
.action(function (options) {
});

program.parse('node test subcommand -a - --bravo - --charlie=-'.split(' '));

program.commands[0].alpha.should.equal('-');
program.commands[0].bravo.should.equal('-');
program.commands[0].charlie.should.equal('-');