
# @cac/option-choices

[![NPM version](https://img.shields.io/npm/v/@cac/option-choices.svg?style=flat)](https://npmjs.com/package/@cac/option-choices) [![NPM downloads](https://img.shields.io/npm/dm/@cac/option-choices.svg?style=flat)](https://npmjs.com/package/@cac/option-choices) [![CircleCI](https://circleci.com/gh/cacjs/option-choices/tree/master.svg?style=shield)](https://circleci.com/gh/cacjs/option-choices/tree/master)  [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate) [![chat](https://img.shields.io/badge/chat-on%20discord-7289DA.svg?style=flat)](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)
