3.0.9 • Published 9 years ago
promisify-cli v3.0.9
promisify-cli
promsifiy-cli is just a cli parser following *nix common line arguments conventions, used by promising way. but it is different.
CLI is just a piece of program, we can just think of it as a function, function requires input and give out results. that's all.
promisify-cli is trying to make cli more intuitive, using it just like invoking a function.
promsifiy-cli converts all command line flags switches and arguments into function params and options.
You can use it building efficient cli tools.
Usage
CLI Files
/*
In package.json adding a new Field `cli`
*/
//WARNING: '-h', '--help', '-v', '--version' are preserved. They are used to print out Usage or Version information.
{
......
cli:[{
"flag": "-p"
//or "flag": "-p --port" specify multiple flags, short/long flags
//or "flag": "-p, --port <port>" indicats *required* param
//or "flag": "-p --port [port]" indicats [optional] param
//"name": "alias name of port" explicitly to customize its name
//"required" : true / false explicitly to specify whether it's optional or must required
//"value": "defaultValue" explicitly assign a default value
//"desc": "description message" descriptin message
},
{
"flag": "--host"
}]
......
}/*
./index.js
*/
var cli = require('../promisify-cli');
//eg cli: startserver -p 80 --host 192.168.28.3 ./www
cli()
.then(function (cli) {
console.log('data->', cli.params, cli.options);
/* params
[
'./www'
]
*/
/* options
{
p: '80',
host: '192.168.28.3'
}
*/
}
})
.catch(function (e) {
console.error('catch->', e.message);
})API
WARNING:
-h,--help,-v,--versionare preserved. They are used to print out Help,Usage,Version information.
cli([flags,options])
functionget cli objectcli.params []
parsed arguments from command line- cli.options {}
parsed flags from command line - cli.help
functionprint out all usage and help information and exit.
Inspired
specially thanks to commander