From dc788daac7845f5cf7a44c2f73c84087441264ef Mon Sep 17 00:00:00 2001 From: iilei Date: Sat, 6 Oct 2018 21:35:55 +0200 Subject: [PATCH] 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. --- index.js | 5 ++++- test/yargs-parser.js | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 357fe227..caf8a646 100644 --- a/index.js +++ b/index.js @@ -372,7 +372,10 @@ function parse (args, opts) { unsetDefaulted(key) if (/-/.test(key) && configuration['camel-case-expansion']) { - addNewAlias(key, camelCase(key)) + var alias = key.split('.').map(function (prop) { + return camelCase(prop) + }).join('.') + addNewAlias(key, alias) } var value = processValue(key, val) diff --git a/test/yargs-parser.js b/test/yargs-parser.js index 62a4965f..b6e2396e 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -1115,6 +1115,15 @@ describe('yargs-parser', function () { argv.fooBar.should.equal(99) }) + + // Fixes: https://github.com/yargs/yargs-parser/issues/77 + it('should combine dot-notation and camel-case expansion', function () { + var argv = parser(['--dot-notation.foo.bar']) + + argv.should.satisfy(function (args) { + return args.dotNotation.foo.bar + }) + }) }) it('should define option as boolean and set default to true', function () {