Search code examples
javascriptcommand-line-argumentsminimist

How to print usage help using minimist?


Here is a simple example from here, which shows the very basics of the minimist command line argument parser:

var minimist = require('minimist')

var args = minimist(process.argv.slice(2), {
  string: 'lang',           // --lang xml
  boolean: ['version'],     // --version
  alias: { v: 'version' }
})

console.log(args)

I want to print the usage of this simple script something like this:

$ node myprog
Usage: myprog [options]

Short description

Options:
  --lang <lang>       sets the language
  --version           output the version number
  -h, --help          output usage information

How can I do this using minimist?

Or should I use another tool like commander?


Solution

  • Finally I have found that minimist is only argument parser and cannot generate decorated usage/help.

    So you should use another tool, like tool like commander.