Skip to content

Commit

Permalink
feat: support boolean which do not consume next argument. (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyfarrell authored and bcoe committed May 5, 2019
1 parent f184308 commit 0ae7fcb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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)) &&
Expand Down
11 changes: 11 additions & 0 deletions test/yargs-parser.js
Expand Up @@ -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']
Expand Down

0 comments on commit 0ae7fcb

Please sign in to comment.