Skip to content

Commit dc788da

Browse files
iileibcoe
authored andcommitted
fix: hyphenated flags combined with dot notation broke parsing (#131)
BREAKING CHANGE: the argv object is now populated differently (correctly) when hyphens and dot notation are used in conjunction.
1 parent 0e366e3 commit dc788da

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,10 @@ function parse (args, opts) {
372372
unsetDefaulted(key)
373373

374374
if (/-/.test(key) && configuration['camel-case-expansion']) {
375-
addNewAlias(key, camelCase(key))
375+
var alias = key.split('.').map(function (prop) {
376+
return camelCase(prop)
377+
}).join('.')
378+
addNewAlias(key, alias)
376379
}
377380

378381
var value = processValue(key, val)

test/yargs-parser.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,15 @@ describe('yargs-parser', function () {
11151115

11161116
argv.fooBar.should.equal(99)
11171117
})
1118+
1119+
// Fixes: https://github.com/yargs/yargs-parser/issues/77
1120+
it('should combine dot-notation and camel-case expansion', function () {
1121+
var argv = parser(['--dot-notation.foo.bar'])
1122+
1123+
argv.should.satisfy(function (args) {
1124+
return args.dotNotation.foo.bar
1125+
})
1126+
})
11181127
})
11191128

11201129
it('should define option as boolean and set default to true', function () {

0 commit comments

Comments
 (0)