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.

Function std.getopt.defaultGetoptPrinter

This function prints the passed Options and text in an aligned manner on stdout.

void defaultGetoptPrinter (
  string text,
  Option[] opt
) @safe;

The passed text will be printed first, followed by a newline, then the short and long version of every option will be printed. The short and long version will be aligned to the longest option of every Option passed. If the option is required, then "Required:" will be printed after the long version of the Option. If a help message is present it will be printed next. The format is illustrated by this code:

foreach (it; opt)
    writefln("%*s %*s%s%s", lengthOfLongestShortOption, it.optShort,
        lengthOfLongestLongOption, it.optLong,
        it.required ? " Required: " : " ",;


text The text to printed at the beginning of the help output.
opt The Option extracted from the getopt parameter.


Andrei Alexandrescu


Boost License 1.0.