Top Description Fields Constructors Methods
io.vertx.core.cli

public Class UsageMessageFormatter

extends Object
Class Inheritance
Known Direct Subclasses
io.vertx.core.impl.launcher.VertxCommandLauncher
Imports
java.io.BufferedReader, .IOException, .StringReader, java.util.*, java.util.stream.Collectors

Usage message formatter.
Author
Clement Escoffier

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_ARG_NAME

default name for an argument

public static final int
DEFAULT_DESC_PAD

number of space characters to be prefixed to each description line

public static final int
DEFAULT_LEFT_PAD

default padding to the left of each line

public static final String
DEFAULT_LONG_OPT_PREFIX

default prefix for long Option

public static final String
DEFAULT_LONG_OPT_SEPARATOR

default separator displayed between a long Option and its value

public static final String
DEFAULT_OPT_PREFIX

default prefix for shortOpts

public static final String
DEFAULT_USAGE_PREFIX

the string to display at the beginning of the usage statement

public static final int
DEFAULT_WIDTH

default number of characters per line

private String
private String
private String
private int
private int
private String
private String
protected Comparator<Option>
optionComparator

Comparator used to sort the options when they output in help text

Defaults to case-insensitive alphabetical sorting by option key.

private String
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
appendArgument(StringBuilder
the StringBuilder to append to
buff
,
Argument
the argument to add
argument
,
boolean
whether the Option is required or not
required
)

Appends the usage clause for an Argument to a StringBuilder.

protected void
appendOption(StringBuilder
the StringBuilder to append to
buff
,
Option
the Option to append
option
)

Appends the usage clause for an Option to a StringBuilder.

public void
buildWrapped(StringBuilder
The buffer to write the help to
buffer
,
String
The text to be written to the buffer
text
)

Builds the specified text to the specified buffer.

public void
buildWrapped(StringBuilder
The buffer to write the help to
buffer
,
int
The position on the next line for the first tab.
nextLineTabStop
,
String
The text to be written to the buffer
text
)

Builds the specified text to the specified buffer.

public void
computeOptionsAndArguments(StringBuilder
The buffer to write the help to
buffer
,
List<Option>
The command line Options
options
,
List<Argument>
the command line Arguments
arguments
)

Computes the help for the specified Options to the specified writer.

public void
computeUsage(StringBuilder buffer, String cmdLineSyntax)

public void
public static String

Returns:

The String of padding
createPadding
(int
The length of the String of padding to create.
len
)

Return a String of padding of length len.

public static int

Returns:

position on which the text must be wrapped or -1 if the wrap position is at the end of the text
findWrapPos
(String
The text being searched for the wrap position
text
,
int
width of the wrapped text
width
,
int
position from which to start the lookup whitespace character
startPos
)

Finds the next text wrap position after startPos for the text in text with the column width width.

public String
public int
public int
public String
public String

Returns:

the separator
getLongOptionSeparator
()

Returns the separator displayed between a long option and its value.

public String
public Comparator<Option>

Returns:

the Comparator currently in use to sort the options
getOptionComparator
()

Comparator used to sort the options when they output in help text.

public String
public String
public int
public static boolean
protected StringBuilder
protected StringBuilder

Returns:

the StringBuilder with the rendered content.
renderOptionsAndArguments
(StringBuilder
The StringBuilder to place the rendered Options and Arguments into.
sb
,
List<Option>
The command line Options
options
,
List<Argument>
The command line Arguments
arguments
)

Renders the specified Options and Arguments and return the rendered output in a StringBuilder.

protected StringBuilder

Returns:

the StringBuilder with the rendered Options contents.
renderWrappedText
(StringBuilder
The StringBuilder to place the rendered text into.
sb
,
int
The number of characters to display per line
width
,
int
The position on the next line for the first tab.
nextLineTabStop
,
String
The text to be rendered.
text
)

Render the specified text and return the rendered Options in a StringBuilder.

public Appendable
renderWrappedTextBlock(StringBuilder
The StringBuilder to place the rendered text into.
sb
,
int
The number of characters to display per line
width
,
int
The position on the next line for the first tab.
nextLineTabStop
,
String
The text to be rendered.
text
)

Renders the specified text width a maximum width.

public static String

Returns:

The String of without the trailing padding
rtrim
(String
The String to remove the trailing padding from.
s
)

Remove the trailing whitespace from the specified String.

public void
public void
setDescPadding(int padding)

public void
setLeftPadding(int padding)

public void
public void
setLongOptionSeparator(String
the separator, typically ' ' or '='.
longOptSeparator
)

Set the separator displayed between a long option and its value.

public void
setNewLine(String newline)

public void
setOptionComparator(Comparator<Option>
the Comparator to use for sorting the options
comparator
)

Set the comparator used to sort the options when they output in help text.

public void
public void
public void
setWidth(int width)

public void
usage(StringBuilder
where the usage is going to be written
builder
,
CLI
the cli
cli
)

Computes the usage of the given CLI.

public void
usage(StringBuilder
where the usage is going to be written
builder
,
String
a prefix to prepend to the usage line. It will be added between 'Usage: ' and the CLI name.
prefix
,
CLI
the cli
cli
)

Computes the usage of the given CLI.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_ARG_NAMEback to summary
public static final String DEFAULT_ARG_NAME

default name for an argument

DEFAULT_DESC_PADback to summary
public static final int DEFAULT_DESC_PAD

number of space characters to be prefixed to each description line

DEFAULT_LEFT_PADback to summary
public static final int DEFAULT_LEFT_PAD

default padding to the left of each line

DEFAULT_LONG_OPT_PREFIXback to summary
public static final String DEFAULT_LONG_OPT_PREFIX

default prefix for long Option

DEFAULT_LONG_OPT_SEPARATORback to summary
public static final String DEFAULT_LONG_OPT_SEPARATOR

default separator displayed between a long Option and its value

DEFAULT_OPT_PREFIXback to summary
public static final String DEFAULT_OPT_PREFIX

default prefix for shortOpts

DEFAULT_USAGE_PREFIXback to summary
public static final String DEFAULT_USAGE_PREFIX

the string to display at the beginning of the usage statement

DEFAULT_WIDTHback to summary
public static final int DEFAULT_WIDTH

default number of characters per line

defaultArgNameback to summary
private String defaultArgName
defaultLongOptPrefixback to summary
private String defaultLongOptPrefix
defaultOptionPrefixback to summary
private String defaultOptionPrefix
descPadback to summary
private int descPad
leftPadback to summary
private int leftPad
longOptSeparatorback to summary
private String longOptSeparator
newLineback to summary
private String newLine
optionComparatorback to summary
protected Comparator<Option> optionComparator

Comparator used to sort the options when they output in help text

Defaults to case-insensitive alphabetical sorting by option key.

usagePrefixback to summary
private String usagePrefix
widthback to summary
private int width

Constructor Detail

UsageMessageFormatterback to summary
public UsageMessageFormatter()

Method Detail

appendArgumentback to summary
protected void appendArgument(StringBuilder buff, Argument argument, boolean required)

Appends the usage clause for an Argument to a StringBuilder.

Parameters
buff:StringBuilder

the StringBuilder to append to

argument:Argument

the argument to add

required:boolean

whether the Option is required or not

appendOptionback to summary
protected void appendOption(StringBuilder buff, Option option)

Appends the usage clause for an Option to a StringBuilder.

Parameters
buff:StringBuilder

the StringBuilder to append to

option:Option

the Option to append

buildWrappedback to summary
public void buildWrapped(StringBuilder buffer, String text)

Builds the specified text to the specified buffer.

Parameters
buffer:StringBuilder

The buffer to write the help to

text:String

The text to be written to the buffer

buildWrappedback to summary
public void buildWrapped(StringBuilder buffer, int nextLineTabStop, String text)

Builds the specified text to the specified buffer.

Parameters
buffer:StringBuilder

The buffer to write the help to

nextLineTabStop:int

The position on the next line for the first tab.

text:String

The text to be written to the buffer

computeOptionsAndArgumentsback to summary
public void computeOptionsAndArguments(StringBuilder buffer, List<Option> options, List<Argument> arguments)

Computes the help for the specified Options to the specified writer.

Parameters
buffer:StringBuilder

The buffer to write the help to

options:List<Option>

The command line Options

arguments:List<Argument>

the command line Arguments

computeUsageback to summary
public void computeUsage(StringBuilder buffer, String cmdLineSyntax)
computeUsageLineback to summary
public void computeUsageLine(StringBuilder buffer, String prefix, CLI cli)
createPaddingback to summary
public static String createPadding(int len)

Return a String of padding of length len.

Parameters
len:int

The length of the String of padding to create.

Returns:String

The String of padding

findWrapPosback to summary
public static int findWrapPos(String text, int width, int startPos)

Finds the next text wrap position after startPos for the text in text with the column width width. 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:String

The text being searched for the wrap position

width:int

width of the wrapped text

startPos:int

position from which to start the lookup whitespace character

Returns:int

position on which the text must be wrapped or -1 if the wrap position is at the end of the text

getArgNameback to summary
public String getArgName()
getDescPaddingback to summary
public int getDescPadding()
getLeftPaddingback to summary
public int getLeftPadding()
getLongOptionPrefixback to summary
public String getLongOptionPrefix()
getLongOptionSeparatorback to summary
public String getLongOptionSeparator()

Returns the separator displayed between a long option and its value.

Returns:String

the separator

getNewLineback to summary
public String getNewLine()
getOptionComparatorback to summary
public Comparator<Option> getOptionComparator()

Comparator used to sort the options when they output in help text. Defaults to case-insensitive alphabetical sorting by option key.

Returns:Comparator<Option>

the Comparator currently in use to sort the options

getOptionPrefixback to summary
public String getOptionPrefix()
getUsagePrefixback to summary
public String getUsagePrefix()
getWidthback to summary
public int getWidth()
isNullOrEmptyback to summary
public static boolean isNullOrEmpty(String s)
renderCommandsback to summary
protected StringBuilder renderCommands(StringBuilder sb, Collection<CLI> commands)
renderOptionsAndArgumentsback to summary
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:StringBuilder

The StringBuilder to place the rendered Options and Arguments into.

options:List<Option>

The command line Options

arguments:List<Argument>

The command line Arguments

Returns:StringBuilder

the StringBuilder with the rendered content.

renderWrappedTextback to summary
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:StringBuilder

The StringBuilder to place the rendered text into.

width:int

The number of characters to display per line

nextLineTabStop:int

The position on the next line for the first tab.

text:String

The text to be rendered.

Returns:StringBuilder

the StringBuilder with the rendered Options contents.

renderWrappedTextBlockback to summary
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:StringBuilder

The StringBuilder to place the rendered text into.

width:int

The number of characters to display per line

nextLineTabStop:int

The position on the next line for the first tab.

text:String

The text to be rendered.

rtrimback to summary
public static String rtrim(String s)

Remove the trailing whitespace from the specified String.

Parameters
s:String

The String to remove the trailing padding from.

Returns:String

The String of without the trailing padding

setArgNameback to summary
public void setArgName(String name)
setDescPaddingback to summary
public void setDescPadding(int padding)
setLeftPaddingback to summary
public void setLeftPadding(int padding)
setLongOptionPrefixback to summary
public void setLongOptionPrefix(String prefix)
setLongOptionSeparatorback to summary
public void setLongOptionSeparator(String longOptSeparator)

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:String

the separator, typically ' ' or '='.

setNewLineback to summary
public void setNewLine(String newline)
setOptionComparatorback to summary
public void setOptionComparator(Comparator<Option> comparator)

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:Comparator<Option>

the Comparator to use for sorting the options

setOptionPrefixback to summary
public void setOptionPrefix(String prefix)
setUsagePrefixback to summary
public void setUsagePrefix(String prefix)
setWidthback to summary
public void setWidth(int width)
usageback to summary
public void usage(StringBuilder builder, CLI cli)

Computes the usage of the given CLI.

Parameters
builder:StringBuilder

where the usage is going to be written

cli:CLI

the cli

usageback to summary
public void usage(StringBuilder builder, String prefix, CLI cli)

Computes the usage of the given CLI.

Parameters
builder:StringBuilder

where the usage is going to be written

prefix:String

a prefix to prepend to the usage line. It will be added between 'Usage: ' and the CLI name.

cli:CLI

the cli