2.0.0 • Published 8 years ago
get-args v2.0.0
get-args
Light arguments parser for Node.js
Installation
You can install get-args using NPM:
$ npm install --save get-argsUsage
var getArgs = require("get-args");arg = getArgs(args)
Returns an object with the result of parsing the array of arguments args. If no array is provided, this will parse the command line arguments passed when the Node.js process was launched, extracted from process.argv.
The output object will have the following keys:
arguments: anarraywith all the arguments that did not have an option associated with it.options: anobjectwith all the single and double hyphened arguments.
var getArgs = require("get-args");
//Parse a
console.log(getArgs(["run", "--file", "/path/to/file.txt", "-x", "5"]));
// { arguments: [ 'run' ],
// options: { file: '/path/to/file.txt', x: '5' } }Run example
There is a script called example.js to test how this module works.
$ node example.js foo bar -i 5 -jkw -y 10 --message "Hello world"
{ arguments: [ 'foo', 'bar' ],
options:
{ i: '5',
j: true,
k: true,
w: true,
y: '10',
message: 'Hello world' } }Limitations
get-argscan't parse arguments with the format--foo=bar.
If you implement a solution that solves anyone of the limitations listed before, feel free to submit your PR.
License
MIT © Josemi Juanes.