docopt

Haxe port of docopt
https://github.com/aurel300/docopt.hx/

To install, run:

haxelib install docopt 0.6.4 

See using Haxelib in Haxelib documentation for more information.

README.md

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 https://github.com/Aurel300/docopt.hx

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.

Example

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.

Usage:
  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

Options:
  -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 ];
    keys.sort(Reflect.compare);
    Sys.println("{"
      + [ 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

Version

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).

Contributors
Aurel300
Version
0.6.4
Published
8 months ago
License
MIT

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! try.haxe.org

Join us on Github!

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

Haxe on Github