Read more

docopt: A promising command line parser for (m)any language

Dominik Schöler
April 30, 2014Software engineer at makandra GmbH

docopt helps you define interface for your command-line app, and automatically generate parser for it.

docopt is based on conventions that are used for decades in help messages and man pages for program interface description. Interface description in docopt is such a help message, but formalized. Here is an example:

Naval Fate.

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

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

In Ruby

^

Docopt::docopt(the_above_doc) # returns:

{"ship"=>true,
 "new"=>false,
 "<name>"=>["Guardian"],
 "move"=>true,
 "<x>"=>"100",
 "<y>"=>"150",
 "--speed"=>"15",
 "shoot"=>false,
 "mine"=>false,
 "set"=>false,
 "remove"=>false,
 "--moored"=>false,
 "--drifting"=>false,
 "--help"=>false,
 "--version"=>false }
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot
Posted by Dominik Schöler to makandra dev (2014-04-30 15:02)