Skip to content

Commit

Permalink
fix: populate positionals when unknown-options-as-args is set (#1508)
Browse files Browse the repository at this point in the history
Closes #1444
  • Loading branch information
mleguen authored and bcoe committed Dec 6, 2019
1 parent 05324b4 commit bb0f2eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/command.js
Expand Up @@ -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)
})
Expand Down
17 changes: 14 additions & 3 deletions test/command.js
Expand Up @@ -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 <bar> [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 <bar> [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', () => {
Expand Down

0 comments on commit bb0f2eb

Please sign in to comment.