cli-commands

A convention for building command-driven CLI apps

MIT 10 个版本
安装
npm install cli-commands
yarn add cli-commands
pnpm add cli-commands
bun add cli-commands
README

view on npm npm module downloads Build Status Dependency Status js-standard-style

cli-commands

A convention for building command-driven CLI apps.

Synopsis

const CliCommands = require('cli-commands')

const validCommands = [
  { name: null },
  { name: 'show', command: require('./command/show').create() },
  { name: 'serve', command: require('./command/serve').create() },
  { name: 'help', command: require('./command/help').create() }
]

const cliCommands = new CliCommands(validCommands)

Where each command looks something like this:

class ShowCommand {
  optionDefinitions () {
    /* command has a --help option */
    return [
      { name: 'help', type: Boolean, alias: 'h' }
    ]
  }
  description () { return 'Print some information.' }
  usage () {
    return [
      { header: 'Options', optionList: this.optionDefinitions() }
    ]
  }
  cliView (data) {
    return JSON.stringify(data, null, '  ')
  }
  execute (options) {
    // do something sync or async
  }
  static create () {
    return new this(...arguments)
  }
}

API Reference

cli-commands

Commands ⏏

Kind: Exported class


© 2016-18 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.

版本列表
0.4.0 2018-04-11
0.3.3 2018-01-15
0.3.2 2017-06-10
0.3.1 2017-06-06
0.3.0 2017-06-06
0.2.1 2017-03-06
0.2.0 2017-01-16
0.1.0 2016-10-23
0.0.1 2016-10-23
0.0.0 2016-10-23