The Gist

Cleopatra got its name because it parses CLI options.

This library parses a command like this:

hhvm script.hh --option foo -vvv -b bar baz

…into something like this:

$program = "script.hh";
$options = Map{"option" => "foo", "v" => 3, "b" => "bar"};
$arguments = Vector{"baz"};

Features

  • Short options
    • Multiple short options can be bundled together (e.g. -abcdef)
    • Short options with required values can be specified either with a space or without (e.g. -d2 or -d 2)
    • Short options with optional values must be specified without a space (e.g. -d2)
    • Short options without values can be bundled with those with values (e.g. -abcd 2)
  • Long options
    • Long options with required values can be specified either with an equals sign or a space (e.g. --foo bar or --foo="bar")
    • Long options with optional values must be specified with an equals sign (e.g. --foo or --foo="bar")
  • Normal arguments
    • Options can be specified in any order among regular arguments (e.g. command -a value -b argument1 --opt="value" -c argument2 argument3)
      • A real-world example of this: aws --profile mine ec2 start-instances --instance-ids i-123456
    • Arguments can be separated from all options with a double dash (e.g. command -a value -xyz -- argument1 argument2 argument3)
  • Automatic help documentation