public class UsageMessageFormatter extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_ARG_NAME
default name for an argument
|
static int |
DEFAULT_DESC_PAD
number of space characters to be prefixed to each description line
|
static int |
DEFAULT_LEFT_PAD
default padding to the left of each line
|
static String |
DEFAULT_LONG_OPT_PREFIX
default prefix for long Option
|
static String |
DEFAULT_LONG_OPT_SEPARATOR
default separator displayed between a long Option and its value
|
static String |
DEFAULT_OPT_PREFIX
default prefix for shortOpts
|
static String |
DEFAULT_USAGE_PREFIX
the string to display at the beginning of the usage statement
|
static int |
DEFAULT_WIDTH
default number of characters per line
|
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.
|
Constructor and Description |
---|
UsageMessageFormatter() |
Modifier and Type | Method and Description |
---|---|
protected void |
appendArgument(StringBuilder buff,
Argument argument,
boolean required)
Appends the usage clause for an Argument to a StringBuilder.
|
protected void |
appendOption(StringBuilder buff,
Option option)
Appends the usage clause for an Option to a StringBuilder.
|
void |
buildWrapped(StringBuilder buffer,
int nextLineTabStop,
String text)
Builds the specified text to the specified buffer.
|
void |
buildWrapped(StringBuilder buffer,
String text)
Builds the specified text to the specified buffer.
|
void |
computeOptionsAndArguments(StringBuilder buffer,
List<Option> options,
List<Argument> arguments)
Computes the help for the specified Options to the specified writer.
|
void |
computeUsage(StringBuilder buffer,
String cmdLineSyntax) |
void |
computeUsageLine(StringBuilder buffer,
String prefix,
CLI cli) |
static String |
createPadding(int len)
Return a String of padding of length
len . |
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 . |
String |
getArgName() |
int |
getDescPadding() |
int |
getLeftPadding() |
String |
getLongOptionPrefix() |
String |
getLongOptionSeparator()
Returns the separator displayed between a long option and its value.
|
String |
getNewLine() |
Comparator<Option> |
getOptionComparator()
Comparator used to sort the options when they output in help text.
|
String |
getOptionPrefix() |
String |
getUsagePrefix() |
int |
getWidth() |
static boolean |
isNullOrEmpty(String s) |
protected StringBuilder |
renderCommands(StringBuilder sb,
Collection<CLI> commands) |
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.
|
protected StringBuilder |
renderWrappedText(StringBuilder sb,
int width,
int nextLineTabStop,
String text)
Render the specified text and return the rendered Options
in a StringBuilder.
|
Appendable |
renderWrappedTextBlock(StringBuilder sb,
int width,
int nextLineTabStop,
String text)
Renders the specified text width a maximum width.
|
static String |
rtrim(String s)
Remove the trailing whitespace from the specified String.
|
void |
setArgName(String name) |
void |
setDescPadding(int padding) |
void |
setLeftPadding(int padding) |
void |
setLongOptionPrefix(String prefix) |
void |
setLongOptionSeparator(String longOptSeparator)
Set the separator displayed between a long option and its value.
|
void |
setNewLine(String newline) |
void |
setOptionComparator(Comparator<Option> comparator)
Set the comparator used to sort the options when they output in help text.
|
void |
setOptionPrefix(String prefix) |
void |
setUsagePrefix(String prefix) |
void |
setWidth(int width) |
void |
usage(StringBuilder builder,
CLI cli)
Computes the usage of the given
CLI . |
void |
usage(StringBuilder builder,
String prefix,
CLI cli)
Computes the usage of the given
CLI . |
public static final int DEFAULT_WIDTH
public static final int DEFAULT_LEFT_PAD
public static final int DEFAULT_DESC_PAD
public static final String DEFAULT_USAGE_PREFIX
public static final String DEFAULT_OPT_PREFIX
public static final String DEFAULT_LONG_OPT_PREFIX
public static final String DEFAULT_LONG_OPT_SEPARATOR
public static final String DEFAULT_ARG_NAME
protected Comparator<Option> optionComparator
public void setWidth(int width)
public int getWidth()
public void setLeftPadding(int padding)
public int getLeftPadding()
public void setDescPadding(int padding)
public int getDescPadding()
public void setUsagePrefix(String prefix)
public String getUsagePrefix()
public void setNewLine(String newline)
public String getNewLine()
public void setOptionPrefix(String prefix)
public String getOptionPrefix()
public void setLongOptionPrefix(String prefix)
public String getLongOptionPrefix()
public void setLongOptionSeparator(String longOptSeparator)
longOptSeparator
- the separator, typically ' ' or '='.public String getLongOptionSeparator()
public void setArgName(String name)
public String getArgName()
public Comparator<Option> getOptionComparator()
Comparator
currently in use to sort the optionspublic void setOptionComparator(Comparator<Option> comparator)
comparator
- the Comparator
to use for sorting the optionsprotected void appendOption(StringBuilder buff, Option option)
buff
- the StringBuilder to append tooption
- the Option to appendprotected void appendArgument(StringBuilder buff, Argument argument, boolean required)
buff
- the StringBuilder to append toargument
- the argument to addrequired
- whether the Option is required or notpublic void usage(StringBuilder builder, CLI cli)
CLI
.builder
- where the usage is going to be writtencli
- the clipublic void usage(StringBuilder builder, String prefix, CLI cli)
CLI
.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 clipublic void computeUsage(StringBuilder buffer, String cmdLineSyntax)
public void computeUsageLine(StringBuilder buffer, String prefix, CLI cli)
public void computeOptionsAndArguments(StringBuilder buffer, List<Option> options, List<Argument> arguments)
buffer
- The buffer to write the help tooptions
- The command line Optionsarguments
- the command line Argumentspublic void buildWrapped(StringBuilder buffer, String text)
buffer
- The buffer to write the help totext
- The text to be written to the bufferpublic void buildWrapped(StringBuilder buffer, int nextLineTabStop, String text)
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 bufferprotected StringBuilder renderCommands(StringBuilder sb, Collection<CLI> commands)
public static boolean isNullOrEmpty(String s)
protected StringBuilder renderOptionsAndArguments(StringBuilder sb, List<Option> options, List<Argument> arguments)
sb
- The StringBuilder to place the rendered Options and Arguments into.options
- The command line Optionsarguments
- The command line Argumentsprotected StringBuilder renderWrappedText(StringBuilder sb, int width, int nextLineTabStop, String text)
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.public Appendable renderWrappedTextBlock(StringBuilder sb, int width, int nextLineTabStop, String text)
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.public static int findWrapPos(String text, int width, int startPos)
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.text
- The text being searched for the wrap positionwidth
- width of the wrapped textstartPos
- position from which to start the lookup whitespace
characterpublic static String createPadding(int len)
len
.len
- The length of the String of padding to create.Copyright © 2022 Eclipse. All rights reserved.