cli-commands

v0.4.0
A convention for building command-driven CLI apps
command-line-commands command-line command commands argv parse option parser

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 <[email protected]>. Documented by jsdoc-to-markdown.

npm i cli-commands

Metadata

  • MIT
  • >=4.0.0
  • Lloyd Brookes
  • released 4/11/2018

Downloads

Maintainers