DefaultHelpPrinter
DefaultHelpPrinter is the help renderer that argparse uses out of the box. It implements HelpPrinter and is the class to derive from in order to customize help screen.
Public data members
config
DefaultHelpPrinter.config holds a config object that was passed to constructor.
style
DefaultHelpPrinter.style holds an actual style that should be applied to the help screen text. This should be used instead of config.style.
Public member functions
Constructor
Constructor of DefaultHelpPrinter initializes an object with specified Config and Style parameters.
Signature
formatCommandUsage
formatCommandUsage returns formatted string for command usage line which is usually Usage: ....
Signature
Parameters
commandNameList of command names including names of parent commands starting with top-level command.
helpInfoHelp info about command.
Return value
String with formatted usage info.
formatArgumentUsage
formatArgumentUsage returns formatted string for argument usage (argument representation in command usage line) which is usually string like [--foo FOO].
Signature
Parameters
helpInfoHelp info about argument.
usageStringIf
truethen the returned value wil be used in usage string, otherwise in argument description.
Return value
String with formatted argument usage info.
formatArgumentValue
formatArgumentValue returns formatted string for argument value: --name <value>. For example, it returns [FOO ...] if argument usage is --foo [FOO ...].
Signature
Parameters
helpInfoHelp info about argument.
Return value
String with formatted argument value.
formatArgumentDescription
formatArgumentDescription returns the description of an argument that is printed next to its name, including the default value of the argument if it should be printed. For example, it returns path to config (default: /etc/app.conf) for an argument that is described as path to config and has /etc/app.conf default value.
Signature
Parameters
helpInfoHelp info about argument.
Return value
String with formatted argument description.
formatArgumentList
formatArgumentList returns a list of arguments formatted the same way the help screen formats them: every argument takes a line with its usage on the left and its description on the right, aligned into two columns and wrapped when needed. It is useful to spell out which arguments a message is about, for example:
Signature
Parameters
argsArguments to be listed.
Return value
String with the formatted list of arguments. Every line, including the last one, is terminated with \n. Empty string if args is empty.
createHelpScreen
This function creates HelpScreen based on list of commands.
Signature
Parameters
commandsCurrent stack of (sub)commands starting with top-level command.
Return value
HelpScreen object with all information about help screen.
createSubCommandGroup
Function that creates a HelpScreen.Group group from CommandHelpInfo data.
Signature
Parameters
cmdCommand that contains subcommands.
Return value
HelpScreen.Group object with subcommand entries.
createArgumentsGroups
Function that creates an array of HelpScreen.Group groups from commands data. Usually this function merges groups with the same names from all commands.
Signature
Parameters
commandsCurrent stack of (sub)commands starting with top-level command.
Return value
Array of HelpScreen.Group objects representing groups of arguments.
printHelp
Function that creates help screen from commands info and prints through sink.
Signature
Parameters
sinkDelegate that receives output in pieces.
commandsCurrent stack of (sub)commands starting with top-level command.
printHelpScreen
This function prints HelpScreen object through sink.
Signature
Parameters
sinkDelegate that receives output in pieces.
screenHelp information to print.
descriptionOffsetScreen offset for parameter description. If help text can be represented as two columns of text,
descriptionOffsetis the position when the second column should start.
printGroup
This function prints HelpScreen.Group object through sink.
Signature
Parameters
sinkDelegate that receives output in pieces.
groupGroup of parameters to print.
descriptionOffsetScreen offset for parameter description. If help text can be represented as two columns of text,
descriptionOffsetis the position when the second column should start.
printParameter
This function prints HelpScreen.Parameter object through sink.
Signature
Parameters
sinkDelegate that receives output in pieces.
paramParameter to print.
descriptionOffsetScreen offset for parameter description. If help text can be represented as two columns of text,
descriptionOffsetis the position when the second column should start.
Public static functions
wrapText
wrapText function wraps text into paragraphs by breaking it up into asequence of lines separated with \n, such that the length of each line does not exceed specific limit. The last line is terminated with \n.
This function is similar to std.string.wrap but with few adjustments:
Styling, if any, is removed during calculation of word length.
Line breaks
\nare preserved. This allows having line breaks where needed in addition to those that are added by function itself.Output is returned via sink in parts rather than in allocated string. Caller can use
appender!stringifstringis needed.
Signature
Parameters
sinkDelegate that receives output in pieces.
textText to be wrapped.
firstIndentString used to indent first line.
indentString used to indent second and following lines.
maxLineLengthMaximum line length.