Socket
Socket
Sign inDemoInstall

commist

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    commist

Build your commands on minimist!


Version published
Weekly downloads
908K
decreased by-2.32%
Maintainers
1
Install size
20.6 kB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 13 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc