fdocopt

0.1.3 • Public • Published

fdocopt npm version

File decorator for docopt option parser.

Description

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 */');

Readme

Keywords

none

Package Sidebar

Install

npm i fdocopt

Weekly Downloads

27

Version

0.1.3

License

Unlicense

Last publish

Collaborators

  • valeriangalliat