Skip to content

polygonal/docopt-ng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Haxe port of docopt-ng

See docopt-ng and docopt and for the original Python implementation.

Example

docopt creates beautiful command-line interfaces:

class Main {
  static function main() {

  var doc = "
    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.
    ";

    try {
      var result = docopt.Docopt.parse( doc, Sys.args() );
      trace( result );
      trace( result.name); // MyShip
    } catch (e) {
      trace( e );
    }
  }
}

The above code is also available in examples/NavalFate.hx which can be run with haxe -L docopt --run NavalFate from within the examples/ directory.

Running the example haxe -L docopt --run NavalFate ship MyShip move 3 4 --speed=10 prints out:

{
 --drifting:false,
     --help:false,
   --moored:false,
    --speed:10,
  --version:false,
     <name>:[MyShip],
        <x>:3,
        <y>:4,
       mine:false,
       move:true,
        new:false,
     remove:false,
        set:false,
       ship:true,
      shoot:false}

The result is of type docopt.ParsedOptions, which is an abstract over Dynamic so you can access the properties via the . operator.

Also see examples/CLIExample.hx for a macro-based example that generates a typed result for autocompletion.

About

Haxe port of docopt-ng

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages