diff --git a/lib/command.js b/lib/command.js index 12a9d8a73..8c6c6ee00 100644 --- a/lib/command.js +++ b/lib/command.js @@ -355,6 +355,7 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) { const unparsed = [] Object.keys(positionalMap).forEach((key) => { positionalMap[key].map((value) => { + if (options.configuration['unknown-options-as-args']) options.key[key] = true unparsed.push(`--${key}`) unparsed.push(value) }) diff --git a/test/command.js b/test/command.js index 6a90f894d..87b098c65 100644 --- a/test/command.js +++ b/test/command.js @@ -39,14 +39,25 @@ describe('Command', () => { .parse() }) - it('populates outer argv with positional arguments', () => { + it('populates outer argv with positional arguments when unknown-options-as-args is not set', () => { const argv = yargs('foo hello world') .command('foo [awesome]') .parse() argv._.should.include('foo') - argv.bar.should.equal('hello') - argv.awesome.should.equal('world') + argv.should.have.property('bar', 'hello') + argv.should.have.property('awesome', 'world') + }) + + it('populates outer argv with positional arguments when unknown-options-as-args is set', () => { + const argv = yargs('foo hello world') + .command('foo [awesome]') + .parserConfiguration({ 'unknown-options-as-args': true }) + .parse() + + argv._.should.include('foo') + argv.should.have.property('bar', 'hello') + argv.should.have.property('awesome', 'world') }) it('populates argv with camel-case variants of arguments when possible', () => {