Command And Conquer, the queen living in your command line.
$ npm install --save cacconst cac = require('cac')
// initialize your cli program
const cli = cac()
// add your very first command
cli.command('hi', 'Say hi!', (input) => {
console.log(`hi ${input[0] || 'boy'}!`)
})
// parse arguments and bootstrap
cli.parse()- Options:
--help-h--version-v - Commands:
help
- options:
string, it could beoptionoroption, aliasoralias, option, the order does not matter. eg:.option('install, i') - description:
string, option description, will be used to output cli usage - defaultValue:
any, give a default value to this option
- commands:
string, it could becommandorcommand, aliasoralias, command, the order does not matter. eg:.command('clone, c'). It can also be a wildcard symbol*, which means always been triggered if no command was specified by user. - description:
string, command description, will be used to output cli usage - fn:
function, command function, will be triggered when this command matches user's input, the function takes two arguments:- input: non-flag arguments
- flags: flags converted to camelCase
- text:
string, the cli usage. default is$bin [options] [commands]
- argv:
array, default isprocess.argv.slice(2)
- handleError:
function, triggered when your program throws an error or was rejected by a Promise call.
a string or array of strings argument names to always treat as strings
a boolean, string or array of strings to always treat as booleans. if true will treat all double hyphenated arguments without equal signs as boolean (e.g. affects --foo, not -f or --foo=bar)
Add an example command for your command, will be shown in CLI usage.
MIT © egoist


