From 2c9051a59fa8e4a1297538a828e9e14592901879 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sun, 13 Oct 2024 14:29:47 +1300 Subject: [PATCH] Update README and examples for allowExcessArguments change (#2266) --- Readme.md | 8 ++++---- examples/pm | 2 +- examples/pm-install | 1 + examples/split.js | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index e4e365787..5b7045be9 100644 --- a/Readme.md +++ b/Readme.md @@ -79,7 +79,8 @@ const { program } = require('commander'); program .option('--first') - .option('-s, --separator '); + .option('-s, --separator ') + .argument(''); program.parse(); @@ -678,8 +679,7 @@ async function main() { } ``` -A command's options and arguments on the command line are validated when the command is used. Any unknown options or missing arguments will be reported as an error. You can suppress the unknown option checks with `.allowUnknownOption()`. By default, it is not an error to -pass more arguments than declared, but you can make this an error with `.allowExcessArguments(false)`. +A command's options and arguments on the command line are validated when the command is used. Any unknown options or missing arguments or excess arguments will be reported as an error. You can suppress the unknown option check with `.allowUnknownOption()`. You can suppress the excess arguments check with `.allowExcessArguments()`. ### Stand-alone executable (sub)commands @@ -696,7 +696,7 @@ Example file: [pm](./examples/pm) program .name('pm') .version('0.1.0') - .command('install [name]', 'install one or more packages') + .command('install [package-names...]', 'install one or more packages') .command('search [query]', 'search with optional query') .command('update', 'update installed packages', { executableFile: 'myUpdateSubCommand' }) .command('list', 'list packages installed', { isDefault: true }); diff --git a/examples/pm b/examples/pm index 831ef1061..fa6dab5e4 100755 --- a/examples/pm +++ b/examples/pm @@ -14,7 +14,7 @@ program .name('pm') .version('0.0.1') .description('Fake package manager') - .command('install [name]', 'install one or more packages') + .command('install [package-names...]', 'install one or more packages') .alias('i') .command('search [query]', 'search with optional query') .alias('s') diff --git a/examples/pm-install b/examples/pm-install index 7ae0c52e5..f5cba6ed5 100755 --- a/examples/pm-install +++ b/examples/pm-install @@ -4,6 +4,7 @@ const { Command } = require('commander'); const program = new Command(); program.option('-f, --force', 'force installation'); +program.argument('[package-names...]'); program.parse(process.argv); diff --git a/examples/split.js b/examples/split.js index 78330d679..f58bd4104 100644 --- a/examples/split.js +++ b/examples/split.js @@ -2,7 +2,7 @@ const { program } = require('commander'); // This is used as an example in the README for the Quick Start. -program.option('--first').option('-s, --separator '); +program.option('--first').option('-s, --separator ').argument(''); program.parse();