$ npm install fdocopt
File decorator for docopt option parser.
It's not easy to work with docopt in pure JavaScript since, unlike Python and CoffeeScript, there's no simple way to define a multiline string to contain the usage string.
This package provides a decorator for docopt to solve this problem.
/*
Usage: hello [options] <world>
Arguments:
<world> Hello world!
Options:
-h, --help Show this help.
--version Show version.
--happy Be happy.
*/
var docopt = require('fdocopt')();
By default it will decorate the global docopt instance, so the above is the same as:
var docopt = require('fdocopt')(require('docopt').docopt);
Then, pass the documented filename instead of the usage string:
var args = docopt(__filename);
You can also use the internal functions to extract the comment block from a file or a code buffer:
var doc = require('fdocopt').extract(__filename);
var doc = require('fdocopt').extractBuffer('/** Usage: hello */');
© 2010 - cnpmjs.org x YWFE | Home | YWFE