diff --git a/index.js b/index.js index 83c69c2c..2f0c17e3 100644 --- a/index.js +++ b/index.js @@ -240,12 +240,12 @@ function parse (args, opts) { } else { next = args[i + 1] - if (next && !/^(-|--)[^-]/.test(next) && + if (next !== undefined && !/^(-|--)[^-]/.test(next) && !checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts)) { setArg(key, next) i++ - } else if (next && /true|false/.test(next)) { + } else if (/true|false/.test(next)) { setArg(key, next) i++ } else { diff --git a/test/yargs-parser.js b/test/yargs-parser.js index 0858b19d..87c54dd7 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -40,6 +40,12 @@ describe('yargs-parser', function () { parse.should.have.property('_').with.length(0) }) + it('should set the value of a single long option to the next supplied value, even if the value is empty', function () { + var parse = parser(['--pow', '']) + parse.should.have.property('pow', '') + parse.should.have.property('_').with.length(0) + }) + it('should set the value of a single long option if an = was used', function () { var parse = parser(['--pow=xixxle']) parse.should.have.property('pow', 'xixxle') @@ -121,6 +127,12 @@ describe('yargs-parser', function () { argv._[0].should.be.a('number') }) + it('should set the value of a single short option to the next supplied value, even if the value is empty', function () { + var parse = parser(['-p', '']) + parse.should.have.property('p', '') + parse.should.have.property('_').with.length(0) + }) + it('should not set the next value as the value of a short option if that option is explicitly defined as a boolean', function () { var parse = parser([ '-t', 'moo' ], { boolean: 't'