node package manager



Rational is (yet another) command line argument parser for node.js. It parses a human readable usage message and infers the arguments, thus making the documentation the direct basis for the code.

It is based on bup's option parser and the corresponding blog post.

It supports boolean/integer and string values, with support for defaults.


npm install rational


API reference

var Rational = require('rational').Rational;
// I swear this is cleaner in CoffeeScript :)
var parser = new Rational('wget [OPTION...] [URL...]\n--\n'+
                        'V,version         display the version of Wget and exit\n'+
                        'h,help            print this help\n'+

                        ' Advanced\n'+
                        'b,background      go to background after startup\n'+
                        'retry-connrefused retry even if connection is refused\n'+

                        ' Vertigo inducing\n'+
                        'g                 download at 1Gbps always\n'+
                        'd                 DDoS the host');

// invoked with wget --no-retry-connrefused -d
var result = parser.parse(process.argv);

background = result.options.background; // false
ddos = result.options.d; // true
retry = result.options['retry-connrefused']; // false

// positional arguments
var urls = result.extras;


Tests are written using vows. To run all tests

$ pwd
$ npm install . --dev # one time only
$ make test


Rational is licensed under the 3-clause Modified BSD License.


Fork and send a pull request :)