HelpPrinter
HelpPrinter is a helper class that is used to create and print help screen.
Public data members
Style
HelpPrinter.style holds a style that should be applied to the help screen text.
Public member functions
Constructor
Constructor of HelpPrinter initializes an object with specified Style parameter.
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.
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.