From 78f401590abbabad634ffe76f754d4cf462bf1fb Mon Sep 17 00:00:00 2001 From: miyajan Date: Sun, 17 Sep 2017 16:28:29 +0900 Subject: [PATCH 1/2] allow "-" hyphen as an option argument with subcommand --- index.js | 2 +- test/test.options.subcommand-hyphen.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/test.options.subcommand-hyphen.js diff --git a/index.js b/index.js index efdd577c3..b24a31cd9 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/test/test.options.subcommand-hyphen.js b/test/test.options.subcommand-hyphen.js new file mode 100644 index 000000000..7ace01d03 --- /dev/null +++ b/test/test.options.subcommand-hyphen.js @@ -0,0 +1,21 @@ +/** + * Module dependencies. + */ + +var program = require('../') + , should = require('should'); + +program + .command('subcommand') + .description('description') + .option('-a, --alpha ', 'hyphen') + .option('-b, --bravo ', 'hyphen') + .option('-c, --charlie ', '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('-'); From aed923dd64d6417fe893b71f1a636e33a8ef4c44 Mon Sep 17 00:00:00 2001 From: jumpei-miyata Date: Tue, 19 Sep 2017 12:37:23 +0900 Subject: [PATCH 2/2] fix indent --- test/test.options.subcommand-hyphen.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/test.options.subcommand-hyphen.js b/test/test.options.subcommand-hyphen.js index 7ace01d03..14d9276cf 100644 --- a/test/test.options.subcommand-hyphen.js +++ b/test/test.options.subcommand-hyphen.js @@ -3,16 +3,16 @@ */ var program = require('../') - , should = require('should'); + , should = require('should'); program - .command('subcommand') - .description('description') - .option('-a, --alpha ', 'hyphen') - .option('-b, --bravo ', 'hyphen') - .option('-c, --charlie ', 'hyphen') - .action(function (options) { - }); + .command('subcommand') + .description('description') + .option('-a, --alpha ', 'hyphen') + .option('-b, --bravo ', 'hyphen') + .option('-c, --charlie ', 'hyphen') + .action(function (options) { + }); program.parse('node test subcommand -a - --bravo - --charlie=-'.split(' '));