Skip to content

Commit

Permalink
Merge branch 'master' into feature/1431-complete-no-flags-when-boolea…
Browse files Browse the repository at this point in the history
…n-negation-is-set
  • Loading branch information
bcoe committed Dec 9, 2019
2 parents a648399 + bb0f2eb commit ea3fe04
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/advanced.md
Expand Up @@ -453,7 +453,7 @@ for detailed documentation of this feature.
### Example
```
yargs
.comand('cmd', ..., async () => {
.command('cmd', ..., async () => {
await this.model.find()
return Promise.resolve('result value')
})
Expand Down
9 changes: 5 additions & 4 deletions docs/api.md
Expand Up @@ -193,6 +193,7 @@ var argv = require('yargs')
.argv
```

<a name="command"></a>
.command(cmd, desc, [builder], [handler])
-----------------------------------------
.command(cmd, desc, [module])
Expand Down Expand Up @@ -1010,9 +1011,9 @@ var argv = require('yargs')
.argv
```

.option(key, [opt])
<a name="option"></a>.option(key, [opt])
-----------------
.options(key, [opt])
<a name="options"></a>.options(key, [opt])
------------------

This method can be used to make yargs aware of options that _could_
Expand Down Expand Up @@ -1175,7 +1176,7 @@ from this location.
------------

`.positional()` allows you to configure a command's positional arguments
with an API similar to [`.option()`](#optionkey-opt). `.positional()`
with an API similar to [`.option()`](#option). `.positional()`
should be called in a command's builder function, and is not
available on the top-level yargs instance.

Expand Down Expand Up @@ -1440,7 +1441,7 @@ Set a usage message to show which commands to use. Inside `message`, the string
present script similar to how `$0` works in bash or perl.

If the optional `desc`/`builder`/`handler` are provided, `.usage()`
acts an an alias for [`.command()`](#commandmodule). This allows you to use
acts an an alias for [`.command()`](#command). This allows you to use
`.usage()` to configure the [default command](/docs/advanced.md#default-commands) that will be run as an entry-point to your application and allows you
to provide configuration for the positional arguments accepted by your program:

Expand Down
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 ea3fe04

Please sign in to comment.