Class HelpFormatter
- java.lang.Object
-
- com.aspectran.shell.command.option.HelpFormatter
-
public class HelpFormatter extends java.lang.Object
A formatter of help messages for command line options.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_DESC_PAD
number of space characters to be prefixed to each description linestatic int
DEFAULT_LEFT_PAD
Default padding to the left of each linestatic int
DEFAULT_MAX_LEFT_WIDTH
Default number of characters per linestatic int
DEFAULT_WIDTH
Default number of characters per linestatic java.lang.String
LONG_OPTION_PREFIX
Default prefix for long Optionstatic java.lang.String
OPTION_PREFIX
Default prefix for shortOpts
-
Constructor Summary
Constructors Constructor Description HelpFormatter(Console console)
Creates a help formatter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getArgName()
int
getDescPad()
int
getLeftPad()
int
getMaxLeftWidth()
java.util.Comparator<Option>
getOptionComparator()
Comparator used to sort the options when they output in help text.java.lang.String
getSyntaxPrefix()
int
getWidth()
void
printArguments(java.util.List<Arguments> argumentsList, int leftWidth)
void
printHelp(Command command)
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(java.lang.String cmdLineSyntax)
Print the help foroptions
with the specified command line syntax.void
printWrapped(java.lang.String text)
Print the specified text to the specified PrintWriter.static void
renderWrappedText(java.lang.StringBuilder sb, int width, int nextLineTabStop, java.lang.String text)
Render the specified text and return the rendered Options in a StringBuilder.void
setArgName(java.lang.String name)
void
setDescPad(int descPad)
void
setLeftPad(int leftPad)
void
setMaxLeftWidth(int maxLeftWidth)
void
setOptionComparator(java.util.Comparator<Option> comparator)
Set the comparator used to sort the options when they output in help text.void
setSyntaxPrefix(java.lang.String prefix)
void
setWidth(int width)
-
-
-
Field Detail
-
DEFAULT_WIDTH
public static final int DEFAULT_WIDTH
Default number of characters per line- See Also:
- Constant Field Values
-
DEFAULT_MAX_LEFT_WIDTH
public static final int DEFAULT_MAX_LEFT_WIDTH
Default number of characters per line- See Also:
- Constant Field Values
-
DEFAULT_LEFT_PAD
public static final int DEFAULT_LEFT_PAD
Default padding to the left of each line- See Also:
- Constant Field Values
-
DEFAULT_DESC_PAD
public static final int DEFAULT_DESC_PAD
number of space characters to be prefixed to each description line- See Also:
- Constant Field Values
-
OPTION_PREFIX
public static final java.lang.String OPTION_PREFIX
Default prefix for shortOpts- See Also:
- Constant Field Values
-
LONG_OPTION_PREFIX
public static final java.lang.String LONG_OPTION_PREFIX
Default prefix for long Option- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HelpFormatter
public HelpFormatter(Console console)
Creates a help formatter.- Parameters:
console
- the console to which the help will be written
-
-
Method Detail
-
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
public java.lang.String getSyntaxPrefix()
-
setSyntaxPrefix
public void setSyntaxPrefix(java.lang.String prefix)
-
getArgName
public java.lang.String getArgName()
-
setArgName
public void setArgName(java.lang.String name)
-
getOptionComparator
public java.util.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:
- the
Comparator
currently in use to sort the options
-
setOptionComparator
public void setOptionComparator(java.util.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
- theComparator
to use for sorting the options
-
printHelp
public void printHelp(Command command)
Print the help with the given Command object.- Parameters:
command
- the Command instance
-
printUsage
public void printUsage(java.lang.String cmdLineSyntax)
Print the help foroptions
with the specified command line syntax.- Parameters:
cmdLineSyntax
- the usage statement
-
printUsage
public void printUsage(Command command)
Prints the usage statement for the specified command.- Parameters:
command
- the Command instance
-
printOptions
public int printOptions(Options options)
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
public void printArguments(java.util.List<Arguments> argumentsList, int leftWidth)
-
printWrapped
public void printWrapped(java.lang.String text)
Print the specified text to the specified PrintWriter.- Parameters:
text
- the text to be written to the PrintWriter
-
renderWrappedText
public static void renderWrappedText(java.lang.StringBuilder sb, int width, int nextLineTabStop, java.lang.String text)
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
-
-