diff --git a/docs/advanced.md b/docs/advanced.md
index 3378b4d28..a72ce1ceb 100644
--- a/docs/advanced.md
+++ b/docs/advanced.md
@@ -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')
})
diff --git a/docs/api.md b/docs/api.md
index 1a9176e51..d5b8d2279 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -193,6 +193,7 @@ var argv = require('yargs')
.argv
```
+
.command(cmd, desc, [builder], [handler])
-----------------------------------------
.command(cmd, desc, [module])
@@ -1010,9 +1011,9 @@ var argv = require('yargs')
.argv
```
-.option(key, [opt])
+.option(key, [opt])
-----------------
-.options(key, [opt])
+.options(key, [opt])
------------------
This method can be used to make yargs aware of options that _could_
@@ -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.
@@ -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:
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', () => {