diff --git a/index.js b/index.js index 67c1385a..546cae06 100644 --- a/index.js +++ b/index.js @@ -186,7 +186,7 @@ function parse (args, opts) { } else if (checkAllAliases(key, flags.arrays) && args.length > i + 1) { i = eatArray(i, key, args) } else { - next = args[i + 1] + next = flags.nargs[key] === 0 ? undefined : args[i + 1] if (next !== undefined && (!next.match(/^-/) || next.match(negative)) && diff --git a/test/yargs-parser.js b/test/yargs-parser.js index ee76e417..c625ce97 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -194,6 +194,17 @@ describe('yargs-parser', function () { parse.should.have.property('_').and.deep.equal(['aaatrueaaa', 'moo', 'aaafalseaaa']) }) + it('should not use next value for boolean configured with zero narg', function () { + var parse = parser(['--all', 'false'], { + boolean: ['all'], + narg: { + all: 0 + } + }) + parse.should.have.property('all', true).and.be.a('boolean') + parse.should.have.property('_').and.deep.equal(['false']) + }) + it('should allow defining options as boolean in groups', function () { var parse = parser([ '-x', '-z', 'one', 'two', 'three' ], { boolean: ['x', 'y', 'z']