Class HelpFormatter
java.lang.Object
com.aspectran.shell.command.option.HelpFormatter
A formatter of help messages for command line options.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
number of space characters to be prefixed to each description linestatic final int
Default padding to the left of each linestatic final int
Default number of characters per linestatic final int
Default number of characters per linestatic final String
Default prefix for long Optionstatic final String
Default prefix for shortOpts -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
int
int
Comparator used to sort the options when they output in help text.int
getWidth()
void
printArguments
(List<Arguments> argumentsList, int leftWidth) void
Print the help with the given Command object.int
printOptions
(Options options) Print the help for the specified Options to the specified writer, using the specified width, left padding and description padding.void
printUsage
(Command command) Prints the usage statement for the specified command.void
printUsage
(String cmdLineSyntax) Print the help foroptions
with the specified command line syntax.void
printWrapped
(String text) Print the specified text to the specified PrintWriter.static void
renderWrappedText
(StringBuilder sb, int width, int nextLineTabStop, String text) Render the specified text and return the rendered Options in a StringBuilder.void
setArgName
(String name) void
setDescPad
(int descPad) void
setLeftPad
(int leftPad) void
setMaxLeftWidth
(int maxLeftWidth) void
setOptionComparator
(Comparator<Option> comparator) Set the comparator used to sort the options when they output in help text.void
setSyntaxPrefix
(String prefix) void
setWidth
(int width)
-
Field Details
-
DEFAULT_WIDTH
public static final int DEFAULT_WIDTHDefault number of characters per line- See Also:
-
DEFAULT_MAX_LEFT_WIDTH
public static final int DEFAULT_MAX_LEFT_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:
-
OPTION_PREFIX
Default prefix for shortOpts- See Also:
-
LONG_OPTION_PREFIX
Default prefix for long Option- See Also:
-
-
Constructor Details
-
HelpFormatter
Creates a help formatter.- Parameters:
console
- the console to which the help will be written
-
-
Method Details
-
getWidth
public int getWidth() -
setWidth
public void setWidth(int width) -
getMaxLeftWidth
public int getMaxLeftWidth() -
setMaxLeftWidth
public void setMaxLeftWidth(int maxLeftWidth) -
getLeftPad
public int getLeftPad() -
setLeftPad
public void setLeftPad(int leftPad) -
getDescPad
public int getDescPad() -
setDescPad
public void setDescPad(int descPad) -
getSyntaxPrefix
-
setSyntaxPrefix
-
getArgName
-
setArgName
-
getOptionComparator
Comparator used to sort the options when they output in help text. Defaults to case-insensitive alphabetical sorting by option key.- Returns:
- the
Comparator
currently 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
- theComparator
to use for sorting the options
-
printHelp
Print the help with the given Command object.- Parameters:
command
- the Command instance
-
printUsage
Print the help foroptions
with the specified command line syntax.- Parameters:
cmdLineSyntax
- the usage statement
-
printUsage
Prints the usage statement for the specified command.- Parameters:
command
- the Command instance
-
printOptions
Print the help for the specified Options to the specified writer, using the specified width, left padding and description padding.- Parameters:
options
- the Options instance- Returns:
- the longest opt string's length
-
printArguments
-
printWrapped
Print the specified text to the specified PrintWriter.- Parameters:
text
- the text to be written to the PrintWriter
-
renderWrappedText
Render the specified text and return the rendered Options in a StringBuilder.- Parameters:
sb
- the StringBuilder to place the rendered text intowidth
- the number of characters to display per linenextLineTabStop
- the position on the next line for the first tabtext
- the text to be rendered
-