View source code
Display the source code in std/getopt.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Module std.getopt

Processing of command line options.

The getopt module implements a getopt function, which adheres to the POSIX syntax for command line options. GNU extensions are supported in the form of long options introduced by a double dash ("--"). Support for bundling of command line options, as was the case with the more traditional single-letter approach, is provided but not enabled by default.

Credits

This module and its documentation are inspired by Perl's Getopt::Long module. The syntax of D's getopt is simpler than its Perl counterpart because getopt infers the expected parameter types from the static types of the passed-in pointers.

Functions

NameDescription
defaultGetoptFormatter(output, text, opt, style) This function writes the passed text and Option into an output range in the manner described in the documentation of function defaultGetoptPrinter, unless the style option is used.
defaultGetoptPrinter(text, opt) This function prints the passed Options and text in an aligned manner on stdout.
getopt(args, opts) Parse and remove command line options from a string array.

Classes

NameDescription
GetOptException Thrown on one of the following conditions:
  • An unrecognized command-line argument is passed, and config.passThrough was not present.
  • A command-line option was not found, and config.required was present.
  • A callback option is missing a value.

Structs

NameDescription
GetoptResult The result of the getopt function.
Option Information about an option.

Enums

NameDescription
config Configuration options for getopt.

Global variables

NameTypeDescription
arraySep string When set to "", parameters to array and associative array receivers are treated as an individual argument. That is, only one argument is appended or inserted per appearance of the option switch. If arraySep is set to something else, then each parameter is first split by the separator, and the individual pieces are treated as arguments to the same option.
assignChar dchar The assignment character used in options with parameters (default '=').
endOfOptions string The string that conventionally marks the end of all options (default '--').
optionChar dchar The option character (default '-').

Authors

Andrei Alexandrescu

License

Boost License 1.0.