commist
Build your commands on minimist!
Last updated 4 years ago by matteo.collina .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install commist 
SYNC missed versions from official npm registry.

commist

Build command line application with multiple commands the easy way. To be used with minimist.

'use strict'

const program = require('commist')()
const result = program
  .register('abcd', function(args) {
    console.log('just do', args)
  })
  .register({ command: 'restore', equals: true }, function(args) {
    console.log('restore', args)
  })
  .register('args', function(args) {
    args = minimist(args)
    console.log('just do', args)
  })
  .register('abcde code', function(args) {
    console.log('doing something', args)
  })
  .register('another command', function(args) {
    console.log('anothering', args)
  })
  .parse(process.argv.splice(2))

if (result) {
  console.log('no command called, args', result)
}

To handle async operations, use parseAsync instead, which let you await on registered commands execution.

'use strict'

const program = require('commist')()

const result = await program
  .register('abcd', async function(args) {
    await executeCommand(args)
    await doOtherStuff()
  })
  .parseAsync(process.argv.splice(2))

if (result) {
  console.log('no command called, args', result)
}

When calling commist programs, you can abbreviate down to three char words. In the above example, these are valid commands:

node example.js abc
node example.js abc cod
node example.js anot comm

Moreover, little spelling mistakes are corrected too:

node example.js abcs cod

If you want that the command must be strict equals, you can register the command with the json configuration:

  program.register({ command: 'restore', strict: true }, function(args) {
    console.log('restore', args)
  })

If you want to limit the maximum levenshtein distance of your commands, you can use maxDistance: 2:

const program = require('commist')()
const minimist = require('minimist')

const result = program
  .register('abcd', function(args) {
    console.log('just do', args)
  })
  .register({ command: 'restore', equals: true }, function(args) {
    console.log('restore', args)
  })
  .register('args', function(args) {
    args = minimist(args)
    console.log('just do', args)
  })
  .register('abcde code', function(args) {
    console.log('doing something', args)
  })
  .register('another command', function(args) {
    console.log('anothering', args)
  })
  .parse(process.argv.splice(2))

if (result) {
  console.log('no command called, args', result)
}

License

MIT

Current Tags

  • 3.2.0                                ...           latest (2 years ago)

10 Versions

  • 3.2.0                                ...           2 years ago
  • 3.1.2                                ...           2 years ago
  • 3.1.1                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.0                                ...           10 years ago
  • 0.2.0                                ...           10 years ago
  • 0.1.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 4
Today 1
This Week 1
This Month 2
Last Day 0
Last Week 1
Last Month 0
Dependencies (2)
Dev Dependencies (4)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE