Add events to minimist, ~30 sloc.
Example usage
var plugins = ;var cli = ; cli; cli;
Install
Install with npm
$ npm i minimist-events --save
Usage
Setup listeners
Use a wildcard to listen to all events:
cli;
Or setup listeners for specific args you want to listen for:
cli; cli; cli; cli;
Parse with minimist
Next, parse arguments. with minimist:
// the `parse` method is a proxy to minimist, // so pass any minimist args to this methodcli;
Complete example
Assuming --foo=bar a b c
is passed on the command line:
var plugins = ;var cli = ; cli;cli;cli;cli; cli;
Tip
process.argv
is just an array, so you can mock command line arguments by just passing an array to cli.parse()
(or minimist if you're not using this lib).
Example:
var args = '--foo' '--bar=baz' 'a' 'b' 'c';cli;
options
help
The only option that minimist-events
currently takes is help
.
If options.help
is true, when minimist returns an empty args object/array, help
is emitted.
var plugins = ;var cli = ; cli; cli;
Events
Array arguments
An event is emitted for the _
array:
params
arr
: the_
array
cli; cli;
Array items
An event is emitted for each item in the _
array.
params
i
: array indexarr
: the_
array
cli;cli;cli; cli;
Array index
An event is also emitted for each array index:
params
item
: array itemarr
: the_
array
cli;cli;cli; cli;
Option arguments
An event is emitted for each option.
Params
val
: the option valueopts
: the args object
cli; cli; cli; cli;
Related projects
- minimist-plugins: Simple wrapper to make minimist pluggable. ~20 sloc.
- minimist: parse argument options
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
Brian Woodward
License
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on August 15, 2015.