@cac/option-choices
Version:
Mark an option as required for specific command.
55 lines (34 loc) • 1.95 kB
Markdown
# @cac/option-choices
[](https://npmjs.com/package/@cac/option-choices) [](https://npmjs.com/package/@cac/option-choices) [](https://circleci.com/gh/cacjs/option-choices/tree/master) [](https://github.com/egoist/donate) [](https://chat.egoist.moe)
Limit valid values for CLI flag to a predefined set of choices, given as an array.
## Install
```bash
yarn add @cac/option-choices
```
## Usage
Your `cli.js`:
```js
const cac = require('cac')
const optionChoices = require('@cac/option-choices')
const cli = cac()
// Apply this plugin
cli.use(optionChoices())
cli.command('init', 'init command', () => console.log('init something'))
.option('fruit', {
choices: ['apple', 'banana'],
desc: 'Choose a fruit'
})
cli.parse()
```
Run `node cli.js --fruit peach` and it will throw:
<img src="https://i.loli.net/2017/12/05/5a26a5a983350.png" width="500" alt="preview">
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
## Author
**@cac/option-choices** © [EGOIST](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>
Authored and maintained by EGOIST with help from contributors ([list](https://github.com/egoist/@cac/option-choices/contributors)).
> [github.com/egoist](https://github.com/egoist) · GitHub [@EGOIST](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)