Flag-parse
A node tool for parse command flag
function
we provide a tool to parse the command flag in node env, if the field has double horizontal line --name=roadhub
, it is a full name ,else if the field has a single horizontal line only,it is a shortcut name -n=roadhub
,it 's value will be map to it's full name's value
> node -f --name=roadhub --age=12 index.js
in index.js
var flag = default /** * default: a default value when process.argv has no this flag * type: is data type for this field , one of `string` , `number` and `bool` * usage: is usage for this field ,it will be print when you call flag.printHelp * shortcut: this is optional field , it is a abbreviation for this field */ let flags = flagflag
you can get this argument in flags, if you forget to config a field , it will be push to rest
by the original order
console // {fork: true, name: "roadhub",}console //["--age=12", "index.js"]flag/** * usage: `git <command> <flag>`, follow flag is useable: * * -name,-n user's name * -fork,-f is fork * * thank you to use git */
thanks