Merge pull request #1026 from abetomo/unify_readme_code_examples_with_const
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Unify readme code examples with 'const'
authored by Tomoaki Abe · committed by GitHub · parents 3b3d3b5, e9c24fe · Browse files · 2 files·+18 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+18 added−18 removed
- other:+18 added−18 removed
Provenance
- Commit
1298a79- Tree
bd29017- Author
Tomoaki Abe <abe@enzou.tokyo>- Committer
GitHub <noreply@github.com>- Parent 1
3b3d3b5- Parent 2
e9c24fe
2 files changed+18 added−18 removed
modified:Readme_zh-CN.md+9 added-9 removed
284 unmodified lines285 286 你可以通过使用 `.arguments` 来为最顶级命令指定参数,对于子命令来说参数都包括在 `.command` 调用之中了。尖括号(e.g. `<required>`)意味着必须的输入,而方括号(e.g. `[optional]`)则是代表了可选的输入287 288 ```js289-var program = require('commander');289+const program = require('commander');290 291 program292 .version('0.1.0')293 .arguments('<cmd> [env]')14 unmodified lines308 309 一个命令有且仅有最后一个参数是可变的,你需要在参数名后加上 `...` 来使它可变,例如310 311 ```js312-var program = require('commander');312+const program = require('commander');313 314 program315 .version('0.1.0')316 .command('rmdir <dir> [otherDirs...]')16 unmodified lines333 你可以使用操作处理程序为一个命令增加选项options。334 操作处理程序会接收每一个你声明的参数的变量,和一个额外的参数——这个命令对象自己。这个命令的参数包括添加的命令特定选项的值。335 336 ```js337-var program = require('commander');337+const program = require('commander');338 339 program340 .command('rm <dir>')341 .option('-r, --recursive', 'Remove recursively')18 unmodified lines360 你可以在可执行文件里处理可执行(子)命令的选项,而不必在顶层声明它们361 362 ```js363 // file: ./examples/pm364-var program = require('commander');364+const program = require('commander');365 366 program367 .version('0.1.0')368 .command('install [name]', 'install one or more packages')35 unmodified lines404 405 ```js406 #!/usr/bin/env node407 408-var program = require('commander');408+const program = require('commander');409 410 program411 .version('0.0.1')412 .option('-f, --foo', 'enable some foo')54 unmodified lines467 可选的回调可在显示帮助文本后处理。468 如果你想显示默认的帮助(例如,如果没有提供命令),你可以使用类似的东西:469 470 ```js471-var program = require('commander');472-var colors = require('colors');471+const program = require('commander');472+const colors = require('colors');473 474 program475 .version('0.1.0')476 .command('getstream [url]', 'get stream URL')70 unmodified lines547 548 ## 例子549 550 ```js551-var program = require('commander');551+const program = require('commander');552 553 program554 .version('0.1.0')555 .option('-C, --chdir <path>', 'change the working directory')4 unmodified lines560 .command('setup [env]')561 .description('run setup commands for all envs')562 .option("-s, --setup_mode [mode]", "Which setup mode to use")563 .action(function(env, options){564- var mode = options.setup_mode || "normal";564+ const mode = options.setup_mode || "normal";565 env = env || 'all';566 console.log('setup for %s env(s) with %s mode', env, mode);567 });568 35 unmodified linesmodified:Readme.md+9 added-9 removed
287 unmodified lines288 289 You use `.arguments` to specify the arguments for the top-level command, and for subcommands they are included in the `.command` call. Angled brackets (e.g. `<required>`) indicate required input. Square brackets (e.g. `[optional]`) indicate optional input.290 291 ```js292-var program = require('commander');292+const program = require('commander');293 294 program295 .version('0.1.0')296 .arguments('<cmd> [env]')15 unmodified lines312 The last argument of a command can be variadic, and only the last argument. To make an argument variadic you313 append `...` to the argument name. For example:314 315 ```js316-var program = require('commander');316+const program = require('commander');317 318 program319 .version('0.1.0')320 .command('rmdir <dir> [otherDirs...]')17 unmodified lines338 The action handler gets passed a parameter for each argument you declared, and one additional argument which is the339 command object itself. This command argument has the values for the command-specific options added as properties.340 341 ```js342-var program = require('commander');342+const program = require('commander');343 344 program345 .command('rm <dir>')346 .option('-r, --recursive', 'Remove recursively')17 unmodified lines364 You handle the options for an executable (sub)command in the executable, and don't declare them at the top-level.365 366 ```js367 // file: ./examples/pm368-var program = require('commander');368+const program = require('commander');369 370 program371 .version('0.1.0')372 .command('install [name]', 'install one or more packages')39 unmodified lines412 413 ```js414 #!/usr/bin/env node415 416-var program = require('commander');416+const program = require('commander');417 418 program419 .version('0.1.0')420 .option('-f, --foo', 'enable some foo')56 unmodified lines477 478 If you want to display help by default (e.g. if no command was provided), you can use something like:479 480 ```js481-var program = require('commander');482-var colors = require('colors');481+const program = require('commander');482+const colors = require('colors');483 484 program485 .version('0.1.0')486 .command('getstream [url]', 'get stream URL')69 unmodified lines556 557 ## Examples558 559 ```js560-var program = require('commander');560+const program = require('commander');561 562 program563 .version('0.1.0')564 .option('-C, --chdir <path>', 'change the working directory')4 unmodified lines569 .command('setup [env]')570 .description('run setup commands for all envs')571 .option("-s, --setup_mode [mode]", "Which setup mode to use")572 .action(function(env, options){573- var mode = options.setup_mode || "normal";573+ const mode = options.setup_mode || "normal";574 env = env || 'all';575 console.log('setup for %s env(s) with %s mode', env, mode);576 });577 35 unmodified lines