Skip to content

Commit

Permalink
feat: handle dot notation boolean options (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssonal authored and bcoe committed Nov 7, 2016
1 parent 2aea6e3 commit 02c3545
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -540,7 +540,7 @@ function parse (args, opts) {
o[key] = increment(o[key])
} else if (o[key] === undefined && checkAllAliases(key, flags.arrays)) {
o[key] = Array.isArray(value) ? value : [value]
} else if (o[key] === undefined || checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
} else if (o[key] === undefined || checkAllAliases(key, flags.bools) || checkAllAliases(keys.join('.'), flags.bools) || checkAllAliases(key, flags.counts)) {
o[key] = value
} else if (Array.isArray(o[key])) {
o[key].push(value)
Expand Down
12 changes: 12 additions & 0 deletions test/yargs-parser.js
Expand Up @@ -198,6 +198,18 @@ describe('yargs-parser', function () {
parse.should.have.property('_').and.deep.equal(['one', 'two', 'three'])
})

it('should correctly parse dot-notation boolean flags', function () {
var parse = parser(['--nested', '--n.v', '--n.y', 'foo'], {
boolean: ['nested', 'n.v']
})

parse.should.have.property('nested', true).and.be.a('boolean')
parse.should.have.property('n').and.deep.equal({
v: true,
y: 'foo'
})
})

it('should preserve newlines in option values', function () {
var args = parser(['-s', 'X\nX'])
args.should.have.property('_').with.length(0)
Expand Down

0 comments on commit 02c3545

Please sign in to comment.