a command line option parser that will make you smile
npm install docoptdocopt – a command line option parser that will make you smile 
===============================================================
> docopt is a language for description of command-line
> interfaces. This is docopt implementation in CoffeeScript, that could
> be used for server-side CoffeeScript and JavaScript programs.
Isn't it awesome how modern command-line arguments parsers generate
help message based on your code?!
Hell no! You know what's awesome? When the option parser is generated
based on the help message that you write yourself! This way you don't need to
write this stupid repeatable parser-code, and instead can write a beautiful
help message (the way you want it!), which adds readability to your code.
Now you can write an awesome, readable, clean, DRY code like this:
``coffeescript
doc = """
Usage:
quick_example.coffee tcp
quick_example.coffee serial
quick_example.coffee -h | --help | --version
"""
{docopt} = require '../docopt'
console.log docopt(doc, version: '0.1.1rc')
`
Hell yeah! The option parser is generated based on doc string above, that youdocopt
pass to the function.
API {docopt} = require 'docopt'
---------------------------------
docopt takes 1 required argument, and 3 optional keyword arguments:
* doc (required) should be a string with the help message, written according
to rules of the docopt language. Here's a quick example:
`bash
Usage: your_program [options]
-h --help Show this.
-v --verbose Print more text.
--quiet Print less text.
-o FILE Specify output file [default: ./test.txt].
`
* argv is an optional argument vector. It defaults to the arguments passedprocess.argv[2..]
to your program (). You can also supply it with an arrayprocess.argv
of strings, as with . For example: ['--verbose', '-o', 'hai.txt'].
* help (default:true) specifies whether the parser should automaticallydoc
print the help message (supplied as ) in case -h or --help options-h
are encountered. After showing the usage-message, the program will terminate.
If you want to handle or --help options manually (the same as other options),help=false
set .
* version (default:null) is an optional argument that specifies the--version
version of your program. If supplied, then, if the parser encounters option, it will print the supplied version and terminate.version could be any printable object, but most likely a string,'2.1.0rc1'
e.g. .
* options_first, by default false. If set to true will
disallow mixing options and positional argument. I.e. after first
positional argument, all arguments will be interpreted as positional
even if the look like options. This can be used for strict
compatibility with POSIX, or if you want to dispatch your arguments
to other programs.
* exit, by default true. If set to false will
cause docopt to throw exceptions instead of printing the error to console and terminating the application.
This flag is mainly for testing purposes.
Note: Although docopt automatically handles -h, --help and --version options,doc
you still need to mention them in the options description () for your users to
know about them.
The return value is an Object with properties (giving long options precedence),
like this:
`javascript``
{'--timeout': '10',
'--baud': '4800',
'--version': false,
'--help': false,
'-h': false,
serial: true,
tcp: false,
'
'