From eacc03568e0ecb9fa1f2224e77d2ad2ba38d7960 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Mon, 19 Nov 2018 23:25:19 +0000 Subject: [PATCH] fix: allows camel-case, variadic arguments, and strict mode to be combined (#1247) --- lib/command.js | 3 +++ test/command.js | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/command.js b/lib/command.js index cc6a53ff5..65ffc4ea5 100644 --- a/lib/command.js +++ b/lib/command.js @@ -358,6 +358,9 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) { Object.keys(parsed.argv).forEach((key) => { if (positionalKeys.indexOf(key) !== -1) { + // any new aliases need to be placed in positionalMap, which + // is used for validation. + if (!positionalMap[key]) positionalMap[key] = parsed.argv[key] argv[key] = parsed.argv[key] } }) diff --git a/test/command.js b/test/command.js index 42d5e3fa5..04ba5e383 100644 --- a/test/command.js +++ b/test/command.js @@ -184,6 +184,17 @@ describe('Command', () => { argv.file.should.equal('file1') argv._.should.include('file2') }) + + // addresses: https://github.com/yargs/yargs/issues/1246 + it('allows camel-case, variadic arguments, and strict mode to be combined', () => { + const argv = yargs('ls one two three') + .command('ls [expandMe...]') + .strict() + .parse() + + argv.expandMe.should.deep.equal(['one', 'two', 'three']) + argv['expand-me'].should.deep.equal(['one', 'two', 'three']) + }) }) describe('missing positional arguments', () => {