From fa3aa3fc008df846e19ea90746b10c176abff254 Mon Sep 17 00:00:00 2001 From: abbr Date: Fri, 25 Apr 2014 21:24:32 -0700 Subject: [PATCH] bug fixing: function normalize doesn't honor option terminator. --- index.js | 6 +++++- test/test.options.hyphen.js | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0566ef1fa..7551bb8e0 100644 --- a/index.js +++ b/index.js @@ -441,7 +441,11 @@ Command.prototype.normalize = function(args){ arg = args[i]; i > 0 && (lastOpt = this.optionFor(args[i-1])); - if (lastOpt && lastOpt.required) { + if(arg==='--'){ + // honor option terminator + ret = ret.concat(args.slice(i)); + break; + } else if (lastOpt && lastOpt.required) { ret.push(arg); } else if (arg.length > 1 && '-' == arg[0] && '-' != arg[1]) { arg.slice(1).split('').forEach(function(c){ diff --git a/test/test.options.hyphen.js b/test/test.options.hyphen.js index 97c552c02..572a85366 100644 --- a/test/test.options.hyphen.js +++ b/test/test.options.hyphen.js @@ -15,9 +15,10 @@ program .option('-b, --bravo ', 'hyphen') .option('-c, --charlie ', 'hyphen') -program.parse('node test -a - --bravo - --charlie=- - -- -'.split(' ')); +program.parse('node test -a - --bravo - --charlie=- - -- - -t1'.split(' ')); program.alpha.should.equal('-'); program.bravo.should.equal('-'); program.charlie.should.equal('-'); program.args[0].should.equal('-'); program.args[1].should.equal('-'); +program.args[2].should.equal('-t1');