Haxe port of docopt

To install, run:

haxelib install docopt 0.6.4 

See using Haxelib in Haxelib documentation for more information.

docopt.hx – Haxe port of docopt

See docopt for the reference Python implementation.

Installing and using

With Haxe installed, simply use haxelib to install:

haxelib git docopt

Then in your compilation arguments, specify:

-lib docopt

The API only consists of the static method org.docopt.Docopt.parse, whose signature is identical to that of the Python reference. See also the example below.


docopt helps you create most beautiful command-line interfaces easily:

import org.docopt.Docopt;

class Main {
  public static function main():Void {
    var arguments = Docopt.parse("Naval Fate.

  naval ship new <name>...
  naval ship <name> move <x> <y> [--speed=<kn>]
  naval ship shoot <x> <y>
  naval mine (set|remove) <x> <y> [--moored | --drifting]
  naval (-h | --help)
  naval --version

  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

", Sys.args(), true, "Naval Fate 2.0");
    // pretty print arguments
    var keys = [ for (k in arguments.keys()) k ];
      + [ for (k in keys) '\'$k\': ${arguments[k]}' ].join(",\n ")
      + "}");

(The above code is also available in the example/ directory with build instructions.)

And that's it. Invoking the above code (compiled to a binary, e.g. using the cpp target) like so:

./naval ship Napoleon move 5 2 --speed=3

Results in:

{'--drifting': false,
 '--help': false,
 '--moored': false,
 '--speed': 3,
 '--version': false,
 '<name>': [Napoleon],
 '<x>': 5,
 '<y>': 2,
 'mine': false,
 'move': true,
 'new': false,
 'remove': false,
 'set': false,
 'ship': true,
 'shoot': false}

Differences from the reference implementation

  • The main class is located in the package org.docopt.Docopt
  • The docopt function is renamed to Docopt.parse, but its signature remains the same


This is docopt.hx version 0.6.3, based on the reference implementation version 0.6.2. It passes all the language-agnostic tests as of the time of writing, on the C++, Javascript, Neko, and PHP targets (see the test/ directory).

8 months ago

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser!

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github