1.0.0 • Published 9 years ago
argv-options v1.0.0
argv-options
argv-options subjectively parses your argv options, i.e., it makes
assumptions about how your CLI is designed to keep the API simple. It expects your argv object to be supplied in the format of -p foo --param bar, i.e.,
simple key-value arguments that may be aliased (using --).
API
parseOptions(argv, options)
This method will return the parsed options in a key-value based object, including all found options and their respective aliases. The following arugments are mandatory:
argvThe arguments array, as space-split array of all parameters. In your average usage case, passingprocess.argv.slice(2)will do.optionsThe possible options, as object:
{
"p": {
"optional": false,
"alias": "param"
},
"a": {
"optional": true,
"alias": "argument"
}
}Parameters are required (optional is false) by default. Alternatively, for
more convenient use, aliases may be specified by using the key's value:
{
"p": "param"
}If any non-optional parameters are missing or undocumented parameters occur,
parseOptions will throw an error.