maximecb/Higgs — pull request #155 by SBSTP (2014-11-17 05:02:20+00:00)
Title: Basic options parser/manager.

The library is a very simple implementation of an option parser. It automatically manages the `--help` and `--version` switches.

It parses the options left to right and expects the arguments to appear before the parameters.
The pattern is:
```shell
cmd arg1 arg2 --param1 --param2 value1 value2 --param3 value3
```

The parameters can have no value (boolean), a single value or multiple values:
* `--bool`
* `--single abc`
* `--multiple abc def`

It is also possible to control the number of argument via the `setArgsRule` method. The method can take a static number of arguments, `setArgsRule(3)` or a minimum and/or maximum `setArgsRule({min: 2, max: 4})`.

The library is also able to detect and display errors if the wrong number of arguments is provided, if a required parameter is not present or if an unknown parameter was provided. When an error is detected, the error is displayed and the program exits.

### API
```js
// module
var options = require('lib/options.js');
options.parse(args:Array[String]) // only parse

// options class
Options(version:String, usage:String) // constructor
Options#setArgsRule(rule:Number|Object) // number or object with min/max
Options#required(name:String, desc:String) // add a required option
Options#optional(name:String, desc:String) // add an optional option
Options#parse(args:Array[String]) // parse and detect errors
Options#help() // show help
Options#version() // show version
```
### Example use
The file `examples/options.js` has a basic example if its use.

### Sample output
```
Errors:

The parameter --op is required.

Usage: math a b c ... [options]

Options:

--op	add or mul. (required)

```