Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: populate positionals when unknown-options-as-args is set #1508

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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