From ee56e3116800824b2b0d6a749950fb7eaac296ff Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 9 Nov 2018 18:12:20 +0200 Subject: [PATCH] fix: handling of one char alias (#139) --- index.js | 2 +- test/yargs-parser.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d003297a..98ee7ae2 100644 --- a/index.js +++ b/index.js @@ -696,7 +696,7 @@ function parse (args, opts) { }) // For "--optionName", also set argv['option-name'] flags.aliases[key].concat(key).forEach(function (x) { - if (/[A-Z]/.test(x) && configuration['camel-case-expansion']) { + if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) { var c = decamelize(x, '-') if (c !== key && flags.aliases[key].indexOf(c) === -1) { flags.aliases[key].push(c) diff --git a/test/yargs-parser.js b/test/yargs-parser.js index 7b52a0be..b0e8555b 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -1218,6 +1218,21 @@ describe('yargs-parser', function () { result.should.have.property('someOption', 'asdf') }) + it('should not apply camel-case logic to 1-character options', function () { + var result = parser(['-p', 'hello'], { + alias: { + p: 'parallel', + P: 'parallel-series' + } + }) + + result.should.not.have.property('P', 'hello') + result.should.not.have.property('parallel-series', 'hello') + result.should.not.have.property('parallelSeries', 'hello') + result.should.have.property('parallel', 'hello') + result.should.have.property('p', 'hello') + }) + it('should provide aliases of options with dashes as camelCase properties', function () { var result = parser([], { alias: {