You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@
16
16
17
17
## Option parsing
18
18
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.
20
20
21
21
```js
22
22
#!/usr/bin/env node
@@ -42,7 +42,7 @@ if (program.bbqSauce) console.log(' - bbq');
42
42
console.log(' - %s cheese', program.cheese);
43
43
```
44
44
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.
46
46
47
47
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.
48
48
@@ -64,6 +64,23 @@ if (program.sauce) console.log(' with sauce');
64
64
elseconsole.log(' without sauce');
65
65
```
66
66
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.
0 commit comments