Update README and examples for allowExcessArguments change (#2266)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by John Gee · committed by GitHub · parent 58c28eb · Browse files · 4 files·+7 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+7 added−6 removed
- other:+7 added−6 removed
Provenance
- Commit
2c9051a- Tree
5172204- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
58c28eb
4 files changed+7 added−6 removed
modified:examples/pm+1 added-1 removed
12 unmodified lines13 program14 .name('pm')15 .version('0.0.1')16 .description('Fake package manager')17- .command('install [name]', 'install one or more packages')17+ .command('install [package-names...]', 'install one or more packages')18 .alias('i')19 .command('search [query]', 'search with optional query')20 .alias('s')21 .command('update', 'update installed packages', {15 unmodified linesmodified:examples/pm-install+1 added
2 unmodified lines3 const { Command } = require('commander');4 const program = new Command();5 6 program.option('-f, --force', 'force installation');7+program.argument('[package-names...]');8 9 program.parse(process.argv);10 11 const pkgs = program.args;12 unmodified linesmodified:examples/split.js+1 added-1 removed
12345567897 unmodified linesconst { program } = require('commander');
// This is used as an example in the README for the Quick Start.
program.option('--first').option('-s, --separator <char>');program.option('--first').option('-s, --separator <char>').argument('<string>');
program.parse();
const options = program.opts();7 unmodified linesmodified:Readme.md+4 added-4 removed
77 unmodified lines78 const { program } = require('commander');79 80 program81 .option('--first')82- .option('-s, --separator <char>');82+ .option('-s, --separator <char>')83+ .argument('<string>');84 85 program.parse();86 87 const options = program.opts();590 unmodified lines678 await program.parseAsync(process.argv);679 }680 ```681 681-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 to682-pass more arguments than declared, but you can make this an error with `.allowExcessArguments(false)`.682+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()`.683 684 ### Stand-alone executable (sub)commands685 686 When `.command()` is invoked with a description argument, this tells Commander that you're going to use stand-alone executables for subcommands.8 unmodified lines695 ```js696 program697 .name('pm')698 .version('0.1.0')699- .command('install [name]', 'install one or more packages')699+ .command('install [package-names...]', 'install one or more packages')700 .command('search [query]', 'search with optional query')701 .command('update', 'update installed packages', { executableFile: 'myUpdateSubCommand' })702 .command('list', 'list packages installed', { isDefault: true });703 454 unmodified lines