Skip to content
Myr

document how to override the version flag

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Dan Allen · committed by Dan Allen · parent 447ce8f · Browse files · 1 file+19 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−2 removed

  • other:+19 added−2 removed

1 file+19 added−2 removed

modified:Readme.md+19 added-2 removed
14 unmodified lines
15 $ npm install commander --save1617## Option parsing1819 Options with commander are defined with the `.option()` method, also serving as documentation for the options. The example below parses args and options from `process.argv`, leaving remaining args as the `program.args` array which were not consumed by options.19Options with commander are defined with the `.option()` method, also serving as documentation for the options. The example below parses args and options from `process.argv`, leaving remaining args as the `program.args` array which were not consumed by options.2021```js22#!/usr/bin/env node23
17 unmodified lines
41if (program.bbqSauce) console.log(' - bbq');42console.log(' - %s cheese', program.cheese);43```4445 Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.45Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.4647Note that multi-word options starting with `--no` prefix negate the boolean value of the following word. For example, `--no-sauce` sets the value of `program.sauce` to false. 4849```js
13 unmodified lines
63if (program.sauce) console.log(' with sauce');64else console.log(' without sauce');65```6667## Version option6869Calling the `version` implicitly adds the `-V` and `--version` options to the command.70When either of these options is present, the command prints the version number and exits.7172 $ ./examples/pizza -V73 0.0.17475If you want your program to respond to the `-v` option instead of the `-V` option, simply pass custom flags to the `version` method using the same syntax as the `option` method.7677```js78program79 .version('0.0.1', '-v, --version')80```8182Now the command will accept the `-v` option instead of the `-V` option.8384## Command-specific options8586You can attach options to a command.87
321 unmodified lines