docopt

fnArgMap docopt(CtfeDoc parsed, string[] argv, bool help = true, string versn = null, bool optionsFirst = false)

Overload of docopt that accepts a compile-time parsed descriptor.

This avoids reparsing the documentation at runtime when a string literal was available at compile time. Semantics are equivalent to the string overload.

fnArgMap docopt(string doc, string[] argv, bool help = true, string versn = null, bool optionsFirst = false)

Parses command-line arguments based on a docopt-style documentation string.

This is the main entry point for the docopt module. It parses the provided arguments according to the interface defined in the documentation string.

Parameters

docThe documentation string defining the command-line interface.
argvThe command-line arguments to parse (excluding program name).
helpWhether to handle --help option automatically (default: true).
versnVersion string for --version option, or null to disable.
optionsFirstWhether options must come before positional arguments.

Returns

An ArgMap containing the parsed argument values.

Throws

DocoptLanguageError if there's an error in the documentation string.

DocoptArgumentError if the arguments don't match the expected pattern. DocoptExitHelp if --help or --version was requested.

Example:

enum DOC = "Usage: prog [options] <file>

Options:
 -h --help     Show this help
 -v --verbose  Be verbose
";

void main(string[] args) {
  try {
     auto arguments = docopt(DOC, args[1..$]);
     if (arguments["--verbose"].isTrue) {
        writeln("Verbose mode enabled");
     }
     writeln("File: ", arguments["<file>"].asString);
  } catch (DocoptExitHelp e) {
     writeln(e.msg);
  } catch (DocoptArgumentError e) {
     writeln("Error: ", e.msg);
  }
}