Command line options helper and usage printer, works well with minimist, inspired by nomnom
Define the allowed options in an array and pass it to 'cliclopts'
var cliclopts = require('cliclopts')
var options = [
{
name: 'verbose',
abbr: 'v',
alias: ['loud'],
boolean: true,
help: 'be verbose'
},
{
name: 'path',
abbr: 'p',
default: './dat.json',
help: 'path to file'
}
]
var cliOpts = cliclopts(options)options is an array of objects with the following possible keys:
nameprimary name of optionabbrone character alias of the optionaliasother options treated as aliasbooleanif true the option is seen as a boolean flaghelpusage string for the optiondefaultdefault value of the option
Returns the usage information as string:
--verbose, -v be verbose
--path, -p path to file (default: "dat.json")
Prints the usage information.
Returns Array of all command names that are specified as boolean.
Returns Object with command names as keys and alias list as value (including abbr)
Returns Object with command names as keys and default values as values.
Returns
{
alias: cliOpts.alias(),
boolean: cliOpts.boolean(),
default: cliOpts.default()
}var allowedOptions = [
{
name: 'verbose',
abbr: 'v',
alias: ['cry-at-me'],
boolean: true,
help: 'be verbose'
},
{
name: 'path',
abbr: 'p',
help: 'path to the file'
},
{
name: 'help',
abbr: 'h',
help: 'show help',
boolean: true
}
]
var cliOpts = require('cliclopts')(allowedOptions)
var argv = require('minimist')(process.argv.slice(2), cliOpts.options())
if (argv.help) {
console.log('Usage: command [options]')
cliOpts.print()
process.exit()
}
yourprogram(argv)
