Skip to content

Commit

Permalink
fix: boolean flag when next value contains the strings 'true' or 'fal…
Browse files Browse the repository at this point in the history
…se'.
  • Loading branch information
elas7 authored and bcoe committed Apr 9, 2016
1 parent 90b871f commit 69941a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function parse (args, opts) {
!checkAllAliases(key, flags.counts)) {
setArg(key, next)
i++
} else if (/true|false/.test(next)) {
} else if (/^(true|false)$/.test(next)) {
setArg(key, next)
i++
} else {
Expand Down
9 changes: 9 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ describe('yargs-parser', function () {
parse.should.have.property('_').and.deep.equal(['moo'])
})

it('should not set boolean options values if the next value only contains the words "true" or "false"', function () {
var parse = parser(['--verbose', 'aaatrueaaa', 'moo', '-t', 'aaafalseaaa'], {
boolean: ['t', 'verbose']
})
parse.should.have.property('verbose', true).and.be.a('boolean')
parse.should.have.property('t', true).and.be.a('boolean')
parse.should.have.property('_').and.deep.equal(['aaatrueaaa', 'moo', 'aaafalseaaa'])
})

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 69941a6

Please sign in to comment.