Skip to content

Commit

Permalink
Merge pull request tj#752 from mojavelinux/document-version-flag
Browse files Browse the repository at this point in the history
document how to override the version flag
  • Loading branch information
abetomo committed Jan 19, 2018
2 parents 447ce8f + 9cee324 commit e5d8f04
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Readme.md
Expand Up @@ -16,7 +16,7 @@

## Option parsing

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.
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.

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

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.
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.

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.

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

## Version option

Calling the `version` implicitly adds the `-V` and `--version` options to the command.
When either of these options is present, the command prints the version number and exits.

$ ./examples/pizza -V
0.0.1

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.

```js
program
.version('0.0.1', '-v, --version')
```

Now the command will accept the `-v` option instead of the `-V` option.

## Command-specific options

You can attach options to a command.
Expand Down

0 comments on commit e5d8f04

Please sign in to comment.