Skip to content

Commit 02c3545

Browse files
ssonalbcoe
authored andcommitted
feat: handle dot notation boolean options (#63)
1 parent 2aea6e3 commit 02c3545

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ function parse (args, opts) {
540540
o[key] = increment(o[key])
541541
} else if (o[key] === undefined && checkAllAliases(key, flags.arrays)) {
542542
o[key] = Array.isArray(value) ? value : [value]
543-
} else if (o[key] === undefined || checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
543+
} else if (o[key] === undefined || checkAllAliases(key, flags.bools) || checkAllAliases(keys.join('.'), flags.bools) || checkAllAliases(key, flags.counts)) {
544544
o[key] = value
545545
} else if (Array.isArray(o[key])) {
546546
o[key].push(value)

test/yargs-parser.js

+12
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ describe('yargs-parser', function () {
198198
parse.should.have.property('_').and.deep.equal(['one', 'two', 'three'])
199199
})
200200

201+
it('should correctly parse dot-notation boolean flags', function () {
202+
var parse = parser(['--nested', '--n.v', '--n.y', 'foo'], {
203+
boolean: ['nested', 'n.v']
204+
})
205+
206+
parse.should.have.property('nested', true).and.be.a('boolean')
207+
parse.should.have.property('n').and.deep.equal({
208+
v: true,
209+
y: 'foo'
210+
})
211+
})
212+
201213
it('should preserve newlines in option values', function () {
202214
var args = parser(['-s', 'X\nX'])
203215
args.should.have.property('_').with.length(0)

0 commit comments

Comments
 (0)