From 0c666a6a32f380c298d46028987af90cc53dff03 Mon Sep 17 00:00:00 2001 From: dappLion <35266934+dapplion@users.noreply.github.com> Date: Wed, 4 Dec 2019 14:23:23 +0100 Subject: [PATCH 1/3] Advanced docs typo 'comand' (#1506) --- docs/advanced.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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') }) From 05324b426025f7bc52b0caeb0794dd61abdd6845 Mon Sep 17 00:00:00 2001 From: Glen Winters Date: Wed, 4 Dec 2019 07:51:26 -0600 Subject: [PATCH 2/3] docs: fix bad anchors in the API docs (#1503) --- docs/api.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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: From bb0f2eb996fa4e19d330b31a01c2036cafa99a7e Mon Sep 17 00:00:00 2001 From: Mael Le Guen Date: Fri, 6 Dec 2019 01:35:27 +0100 Subject: [PATCH 3/3] fix: populate positionals when unknown-options-as-args is set (#1508) Closes #1444 --- lib/command.js | 1 + test/command.js | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) 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', () => {