Skip to content
Myr

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

4 files+7 added−6 removed

modified:examples/pm+1 added-1 removed
12 unmodified lines
13program14 .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 lines
modified:examples/pm-install+1 added
2 unmodified lines
3const { Command } = require('commander');4const program = new Command();56program.option('-f, --force', 'force installation');7program.argument('[package-names...]');89program.parse(process.argv);1011const pkgs = program.args;
12 unmodified lines
modified:examples/split.js+1 added-1 removed
modified:Readme.md+4 added-4 removed
77 unmodified lines
78const { program } = require('commander');7980program81 .option('--first')82 .option('-s, --separator <char>');82 .option('-s, --separator <char>')83 .argument('<string>');8485program.parse();8687const options = program.opts();
590 unmodified lines
678 await program.parseAsync(process.argv);679}680```681681A 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 to682pass more arguments than declared, but you can make this an error with `.allowExcessArguments(false)`.682A 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()`.683684### Stand-alone executable (sub)commands685686When `.command()` is invoked with a description argument, this tells Commander that you're going to use stand-alone executables for subcommands.
8 unmodified lines
695```js696program697 .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