Class UsageMessageFormatter
java.lang.Object
io.vertx.core.cli.UsageMessageFormatter
- Direct Known Subclasses:
io.vertx.core.impl.launcher.VertxCommandLauncher
Usage message formatter.
- Author:
- Clement Escoffier invalid input: '<'[email protected]>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringdefault name for an argumentstatic final intnumber of space characters to be prefixed to each description linestatic final intdefault padding to the left of each linestatic final Stringdefault prefix for long Optionstatic final Stringdefault separator displayed between a long Option and its valuestatic final Stringdefault prefix for shortOptsstatic final Stringthe string to display at the beginning of the usage statementstatic final intdefault number of characters per lineprotected Comparator<Option> Comparator used to sort the options when they output in help text -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendArgument(StringBuilder buff, Argument argument, boolean required) Appends the usage clause for an Argument to a StringBuilder.protected voidappendOption(StringBuilder buff, Option option) Appends the usage clause for an Option to a StringBuilder.voidbuildWrapped(StringBuilder buffer, int nextLineTabStop, String text) Builds the specified text to the specified buffer.voidbuildWrapped(StringBuilder buffer, String text) Builds the specified text to the specified buffer.voidcomputeOptionsAndArguments(StringBuilder buffer, List<Option> options, List<Argument> arguments) Computes the help for the specified Options to the specified writer.voidcomputeUsage(StringBuilder buffer, String cmdLineSyntax) voidcomputeUsageLine(StringBuilder buffer, String prefix, CLI cli) static StringcreatePadding(int len) Return a String of padding of lengthlen.static intfindWrapPos(String text, int width, int startPos) Finds the next text wrap position afterstartPosfor the text intextwith the column widthwidth.intintReturns the separator displayed between a long option and its value.Comparator used to sort the options when they output in help text.intgetWidth()static booleanprotected StringBuilderrenderCommands(StringBuilder sb, Collection<CLI> commands) protected StringBuilderrenderOptionsAndArguments(StringBuilder sb, List<Option> options, List<Argument> arguments) Renders the specified Options and Arguments and return the rendered output in a StringBuilder.protected StringBuilderrenderWrappedText(StringBuilder sb, int width, int nextLineTabStop, String text) Render the specified text and return the rendered Options in a StringBuilder.renderWrappedTextBlock(StringBuilder sb, int width, int nextLineTabStop, String text) Renders the specified text width a maximum width.static StringRemove the trailing whitespace from the specified String.voidsetArgName(String name) voidsetDescPadding(int padding) voidsetLeftPadding(int padding) voidsetLongOptionPrefix(String prefix) voidsetLongOptionSeparator(String longOptSeparator) Set the separator displayed between a long option and its value.voidsetNewLine(String newline) voidsetOptionComparator(Comparator<Option> comparator) Set the comparator used to sort the options when they output in help text.voidsetOptionPrefix(String prefix) voidsetUsagePrefix(String prefix) voidsetWidth(int width) voidusage(StringBuilder builder, CLI cli) Computes the usage of the givenCLI.voidusage(StringBuilder builder, String prefix, CLI cli) Computes the usage of the givenCLI.
-
Field Details
-
DEFAULT_WIDTH
public static final int DEFAULT_WIDTHdefault number of characters per line- See Also:
-
DEFAULT_LEFT_PAD
public static final int DEFAULT_LEFT_PADdefault padding to the left of each line- See Also:
-
DEFAULT_DESC_PAD
public static final int DEFAULT_DESC_PADnumber of space characters to be prefixed to each description line- See Also:
-
DEFAULT_USAGE_PREFIX
the string to display at the beginning of the usage statement- See Also:
-
DEFAULT_OPT_PREFIX
-
DEFAULT_LONG_OPT_PREFIX
-
DEFAULT_LONG_OPT_SEPARATOR
default separator displayed between a long Option and its value- See Also:
-
DEFAULT_ARG_NAME
-
optionComparator
Comparator used to sort the options when they output in help text Defaults to case-insensitive alphabetical sorting by option key.
-
-
Constructor Details
-
UsageMessageFormatter
public UsageMessageFormatter()
-
-
Method Details
-
setWidth
public void setWidth(int width) -
getWidth
public int getWidth() -
setLeftPadding
public void setLeftPadding(int padding) -
getLeftPadding
public int getLeftPadding() -
setDescPadding
public void setDescPadding(int padding) -
getDescPadding
public int getDescPadding() -
setUsagePrefix
-
getUsagePrefix
-
setNewLine
-
getNewLine
-
setOptionPrefix
-
getOptionPrefix
-
setLongOptionPrefix
-
getLongOptionPrefix
-
setLongOptionSeparator
Set the separator displayed between a long option and its value. Ensure that the separator specified is supported by the parser used, typically ' ' or '='.- Parameters:
longOptSeparator- the separator, typically ' ' or '='.
-
getLongOptionSeparator
Returns the separator displayed between a long option and its value.- Returns:
- the separator
-
setArgName
-
getArgName
-
getOptionComparator
Comparator used to sort the options when they output in help text. Defaults to case-insensitive alphabetical sorting by option key.- Returns:
- the
Comparatorcurrently in use to sort the options
-
setOptionComparator
Set the comparator used to sort the options when they output in help text. Passing in a null comparator will keep the options in the order they were declared.- Parameters:
comparator- theComparatorto use for sorting the options
-
appendOption
Appends the usage clause for an Option to a StringBuilder.- Parameters:
buff- the StringBuilder to append tooption- the Option to append
-
appendArgument
Appends the usage clause for an Argument to a StringBuilder.- Parameters:
buff- the StringBuilder to append toargument- the argument to addrequired- whether the Option is required or not
-
usage
Computes the usage of the givenCLI.- Parameters:
builder- where the usage is going to be writtencli- the cli
-
usage
Computes the usage of the givenCLI.- Parameters:
builder- where the usage is going to be writtenprefix- a prefix to prepend to the usage line. It will be added between 'Usage: ' and the CLI name.cli- the cli
-
computeUsage
-
computeUsageLine
-
computeOptionsAndArguments
public void computeOptionsAndArguments(StringBuilder buffer, List<Option> options, List<Argument> arguments) Computes the help for the specified Options to the specified writer.- Parameters:
buffer- The buffer to write the help tooptions- The command line Optionsarguments- the command line Arguments
-
buildWrapped
Builds the specified text to the specified buffer.- Parameters:
buffer- The buffer to write the help totext- The text to be written to the buffer
-
buildWrapped
Builds the specified text to the specified buffer.- Parameters:
buffer- The buffer to write the help tonextLineTabStop- The position on the next line for the first tab.text- The text to be written to the buffer
-
renderCommands
-
isNullOrEmpty
-
renderOptionsAndArguments
protected StringBuilder renderOptionsAndArguments(StringBuilder sb, List<Option> options, List<Argument> arguments) Renders the specified Options and Arguments and return the rendered output in a StringBuilder.- Parameters:
sb- The StringBuilder to place the rendered Options and Arguments into.options- The command line Optionsarguments- The command line Arguments- Returns:
- the StringBuilder with the rendered content.
-
renderWrappedText
protected StringBuilder renderWrappedText(StringBuilder sb, int width, int nextLineTabStop, String text) Render the specified text and return the rendered Options in a StringBuilder.- Parameters:
sb- The StringBuilder to place the rendered text into.width- The number of characters to display per linenextLineTabStop- The position on the next line for the first tab.text- The text to be rendered.- Returns:
- the StringBuilder with the rendered Options contents.
-
renderWrappedTextBlock
public Appendable renderWrappedTextBlock(StringBuilder sb, int width, int nextLineTabStop, String text) Renders the specified text width a maximum width. This method differs from renderWrappedText by not removing leading spaces after a new line.- Parameters:
sb- The StringBuilder to place the rendered text into.width- The number of characters to display per linenextLineTabStop- The position on the next line for the first tab.text- The text to be rendered.
-
findWrapPos
Finds the next text wrap position afterstartPosfor the text intextwith the column widthwidth. The wrap point is the last position before startPos+width having a whitespace character (space, \n, \r). If there is no whitespace character before startPos+width, it will return startPos+width.- Parameters:
text- The text being searched for the wrap positionwidth- width of the wrapped textstartPos- position from which to start the lookup whitespace character- Returns:
- position on which the text must be wrapped or -1 if the wrap position is at the end of the text
-
createPadding
Return a String of padding of lengthlen.- Parameters:
len- The length of the String of padding to create.- Returns:
- The String of padding
-
rtrim
-