@cac/option-choices

2.0.1 • Public • Published

@cac/option-choices

NPM version NPM downloads CircleCI donate chat

Limit valid values for CLI flag to a predefined set of choices, given as an array.

Install

yarn add @cac/option-choices

Usage

Your cli.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:

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, Released under the MIT License.
Authored and maintained by EGOIST with help from contributors (list).

github.com/egoist · GitHub @EGOIST · Twitter @_egoistlily

Package Sidebar

Install

npm i @cac/option-choices

Weekly Downloads

0

Version

2.0.1

License

MIT

Last publish

Collaborators

  • kchan
  • rem