Class HelpFormatter
- java.lang.Object
-
- com.aspectran.shell.command.option.HelpFormatter
-
public class HelpFormatter extends java.lang.ObjectA formatter of help messages for command line options.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_DESC_PADnumber of space characters to be prefixed to each description linestatic intDEFAULT_LEFT_PADDefault padding to the left of each linestatic intDEFAULT_MAX_LEFT_WIDTHDefault number of characters per linestatic intDEFAULT_WIDTHDefault number of characters per linestatic java.lang.StringLONG_OPTION_PREFIXDefault prefix for long Optionstatic java.lang.StringOPTION_PREFIXDefault 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.StringgetArgName()intgetDescPad()intgetLeftPad()intgetMaxLeftWidth()java.util.Comparator<Option>getOptionComparator()Comparator used to sort the options when they output in help text.java.lang.StringgetSyntaxPrefix()intgetWidth()voidprintArguments(java.util.List<Arguments> argumentsList, int leftWidth)voidprintHelp(Command command)Print the help with the given Command object.intprintOptions(Options options)Print the help for the specified Options to the specified writer, using the specified width, left padding and description padding.voidprintUsage(Command command)Prints the usage statement for the specified command.voidprintUsage(java.lang.String cmdLineSyntax)Print the help foroptionswith the specified command line syntax.voidprintWrapped(java.lang.String text)Print the specified text to the specified PrintWriter.static voidrenderWrappedText(java.lang.StringBuilder sb, int width, int nextLineTabStop, java.lang.String text)Render the specified text and return the rendered Options in a StringBuilder.voidsetArgName(java.lang.String name)voidsetDescPad(int descPad)voidsetLeftPad(int leftPad)voidsetMaxLeftWidth(int maxLeftWidth)voidsetOptionComparator(java.util.Comparator<Option> comparator)Set the comparator used to sort the options when they output in help text.voidsetSyntaxPrefix(java.lang.String prefix)voidsetWidth(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
Comparatorcurrently 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- theComparatorto 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 foroptionswith 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
-
-