Skip to content

Commit e5d8f04

Browse files
authored
Merge pull request #752 from mojavelinux/document-version-flag
document how to override the version flag
2 parents 447ce8f + 9cee324 commit e5d8f04

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Readme.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
## Option parsing
1818

19-
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.
19+
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.
2020

2121
```js
2222
#!/usr/bin/env node
@@ -42,7 +42,7 @@ if (program.bbqSauce) console.log(' - bbq');
4242
console.log(' - %s cheese', program.cheese);
4343
```
4444

45-
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.
45+
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.
4646

4747
Note 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.
4848

@@ -64,6 +64,23 @@ if (program.sauce) console.log(' with sauce');
6464
else console.log(' without sauce');
6565
```
6666

67+
## Version option
68+
69+
Calling the `version` implicitly adds the `-V` and `--version` options to the command.
70+
When either of these options is present, the command prints the version number and exits.
71+
72+
$ ./examples/pizza -V
73+
0.0.1
74+
75+
If 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.
76+
77+
```js
78+
program
79+
.version('0.0.1', '-v, --version')
80+
```
81+
82+
Now the command will accept the `-v` option instead of the `-V` option.
83+
6784
## Command-specific options
6885

6986
You can attach options to a command.

0 commit comments

Comments
 (0)