public class HelpFormatter
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
HelpFormatter.OptionComparator
This class implements the
Comparator interface
for comparing Options. |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_ARG_NAME
default name for an argument
|
static int |
DEFAULT_DESC_PAD
the number of characters of padding to be prefixed
to each description line
|
static int |
DEFAULT_LEFT_PAD
default padding to the left of each line
|
static java.lang.String |
DEFAULT_LONG_OPT_PREFIX
default prefix for long Option
|
static java.lang.String |
DEFAULT_OPT_PREFIX
default prefix for shortOpts
|
static java.lang.String |
DEFAULT_SYNTAX_PREFIX
the string to display at the begining of the usage statement
|
static int |
DEFAULT_WIDTH
default number of characters per line
|
java.lang.String |
defaultArgName
Deprecated.
Scope will be made private for next major version
- use get/setArgName methods instead.
|
int |
defaultDescPad
Deprecated.
Scope will be made private for next major version
- use get/setDescPadding methods instead.
|
int |
defaultLeftPad
Deprecated.
Scope will be made private for next major version
- use get/setLeftPadding methods instead.
|
java.lang.String |
defaultLongOptPrefix
Deprecated.
Scope will be made private for next major version
- use get/setLongOptPrefix methods instead.
|
java.lang.String |
defaultNewLine
Deprecated.
Scope will be made private for next major version
- use get/setNewLine methods instead.
|
java.lang.String |
defaultOptPrefix
Deprecated.
Scope will be made private for next major version
- use get/setOptPrefix methods instead.
|
java.lang.String |
defaultSyntaxPrefix
Deprecated.
Scope will be made private for next major version
- use get/setSyntaxPrefix methods instead.
|
int |
defaultWidth
Deprecated.
Scope will be made private for next major version
- use get/setWidth methods instead.
|
Constructor and Description |
---|
HelpFormatter() |
Modifier and Type | Method and Description |
---|---|
private static void |
appendOption(java.lang.StringBuffer buff,
Option option,
boolean required)
Appends the usage clause for an Option to a StringBuffer.
|
private static void |
appendOptionGroup(java.lang.StringBuffer buff,
OptionGroup group)
Appends the usage clause for an OptionGroup to a StringBuffer.
|
protected java.lang.String |
createPadding(int len)
Return a String of padding of length
len . |
protected int |
findWrapPos(java.lang.String text,
int width,
int startPos)
Finds the next text wrap position after
startPos for the
text in text with the column width width . |
java.lang.String |
getArgName()
Returns the 'argName'.
|
int |
getDescPadding()
Returns the 'descPadding'.
|
int |
getLeftPadding()
Returns the 'leftPadding'.
|
java.lang.String |
getLongOptPrefix()
Returns the 'longOptPrefix'.
|
java.lang.String |
getNewLine()
Returns the 'newLine'.
|
java.lang.String |
getOptPrefix()
Returns the 'optPrefix'.
|
java.lang.String |
getSyntaxPrefix()
Returns the 'syntaxPrefix'.
|
int |
getWidth()
Returns the 'width'.
|
void |
printHelp(int width,
java.lang.String cmdLineSyntax,
java.lang.String header,
Options options,
java.lang.String footer)
Print the help for
options with the specified
command line syntax. |
void |
printHelp(int width,
java.lang.String cmdLineSyntax,
java.lang.String header,
Options options,
java.lang.String footer,
boolean autoUsage)
Print the help for
options with the specified
command line syntax. |
void |
printHelp(java.io.PrintWriter pw,
int width,
java.lang.String cmdLineSyntax,
java.lang.String header,
Options options,
int leftPad,
int descPad,
java.lang.String footer)
Print the help for
options with the specified
command line syntax. |
void |
printHelp(java.io.PrintWriter pw,
int width,
java.lang.String cmdLineSyntax,
java.lang.String header,
Options options,
int leftPad,
int descPad,
java.lang.String footer,
boolean autoUsage)
Print the help for
options with the specified
command line syntax. |
void |
printHelp(java.lang.String cmdLineSyntax,
Options options)
Print the help for
options with the specified
command line syntax. |
void |
printHelp(java.lang.String cmdLineSyntax,
Options options,
boolean autoUsage)
Print the help for
options with the specified
command line syntax. |
void |
printHelp(java.lang.String cmdLineSyntax,
java.lang.String header,
Options options,
java.lang.String footer)
Print the help for
options with the specified
command line syntax. |
void |
printHelp(java.lang.String cmdLineSyntax,
java.lang.String header,
Options options,
java.lang.String footer,
boolean autoUsage)
Print the help for
options with the specified
command line syntax. |
void |
printOptions(java.io.PrintWriter pw,
int width,
Options options,
int leftPad,
int descPad)
Print the help for the specified Options to the specified writer,
using the specified width, left padding and description padding.
|
void |
printUsage(java.io.PrintWriter pw,
int width,
java.lang.String cmdLineSyntax)
Print the cmdLineSyntax to the specified writer, using the
specified width.
|
void |
printUsage(java.io.PrintWriter pw,
int width,
java.lang.String app,
Options options)
Prints the usage statement for the specified application.
|
void |
printWrapped(java.io.PrintWriter pw,
int width,
int nextLineTabStop,
java.lang.String text)
Print the specified text to the specified PrintWriter.
|
void |
printWrapped(java.io.PrintWriter pw,
int width,
java.lang.String text)
Print the specified text to the specified PrintWriter.
|
protected java.lang.StringBuffer |
renderOptions(java.lang.StringBuffer sb,
int width,
Options options,
int leftPad,
int descPad)
Render the specified Options and return the rendered Options
in a StringBuffer.
|
protected java.lang.StringBuffer |
renderWrappedText(java.lang.StringBuffer sb,
int width,
int nextLineTabStop,
java.lang.String text)
Render the specified text and return the rendered Options
in a StringBuffer.
|
protected java.lang.String |
rtrim(java.lang.String s)
Remove the trailing whitespace from the specified String.
|
void |
setArgName(java.lang.String name)
Sets the 'argName'.
|
void |
setDescPadding(int padding)
Sets the 'descPadding'.
|
void |
setLeftPadding(int padding)
Sets the 'leftPadding'.
|
void |
setLongOptPrefix(java.lang.String prefix)
Sets the 'longOptPrefix'.
|
void |
setNewLine(java.lang.String newline)
Sets the 'newLine'.
|
void |
setOptPrefix(java.lang.String prefix)
Sets the 'optPrefix'.
|
void |
setSyntaxPrefix(java.lang.String prefix)
Sets the 'syntaxPrefix'.
|
void |
setWidth(int width)
Sets the 'width'.
|
public static final int DEFAULT_WIDTH
public static final int DEFAULT_LEFT_PAD
public static final int DEFAULT_DESC_PAD
public static final java.lang.String DEFAULT_SYNTAX_PREFIX
public static final java.lang.String DEFAULT_OPT_PREFIX
public static final java.lang.String DEFAULT_LONG_OPT_PREFIX
public static final java.lang.String DEFAULT_ARG_NAME
public int defaultWidth
public int defaultLeftPad
public int defaultDescPad
public java.lang.String defaultSyntaxPrefix
public java.lang.String defaultNewLine
public java.lang.String defaultOptPrefix
public java.lang.String defaultLongOptPrefix
public java.lang.String defaultArgName
public void setWidth(int width)
width
- the new value of 'width'public int getWidth()
public void setLeftPadding(int padding)
padding
- the new value of 'leftPadding'public int getLeftPadding()
public void setDescPadding(int padding)
padding
- the new value of 'descPadding'public int getDescPadding()
public void setSyntaxPrefix(java.lang.String prefix)
prefix
- the new value of 'syntaxPrefix'public java.lang.String getSyntaxPrefix()
public void setNewLine(java.lang.String newline)
newline
- the new value of 'newLine'public java.lang.String getNewLine()
public void setOptPrefix(java.lang.String prefix)
prefix
- the new value of 'optPrefix'public java.lang.String getOptPrefix()
public void setLongOptPrefix(java.lang.String prefix)
prefix
- the new value of 'longOptPrefix'public java.lang.String getLongOptPrefix()
public void setArgName(java.lang.String name)
name
- the new value of 'argName'public java.lang.String getArgName()
public void printHelp(java.lang.String cmdLineSyntax, Options options)
Print the help for options
with the specified
command line syntax. This method prints help information to
System.out.
cmdLineSyntax
- the syntax for this applicationoptions
- the Options instancepublic void printHelp(java.lang.String cmdLineSyntax, Options options, boolean autoUsage)
Print the help for options
with the specified
command line syntax. This method prints help information to
System.out.
cmdLineSyntax
- the syntax for this applicationoptions
- the Options instanceautoUsage
- whether to print an automatically generated
usage statementpublic void printHelp(java.lang.String cmdLineSyntax, java.lang.String header, Options options, java.lang.String footer)
Print the help for options
with the specified
command line syntax. This method prints help information to
System.out.
cmdLineSyntax
- the syntax for this applicationheader
- the banner to display at the begining of the helpoptions
- the Options instancefooter
- the banner to display at the end of the helppublic void printHelp(java.lang.String cmdLineSyntax, java.lang.String header, Options options, java.lang.String footer, boolean autoUsage)
Print the help for options
with the specified
command line syntax. This method prints help information to
System.out.
cmdLineSyntax
- the syntax for this applicationheader
- the banner to display at the begining of the helpoptions
- the Options instancefooter
- the banner to display at the end of the helpautoUsage
- whether to print an automatically generated
usage statementpublic void printHelp(int width, java.lang.String cmdLineSyntax, java.lang.String header, Options options, java.lang.String footer)
Print the help for options
with the specified
command line syntax. This method prints help information to
System.out.
width
- the number of characters to be displayed on each linecmdLineSyntax
- the syntax for this applicationheader
- the banner to display at the begining of the helpoptions
- the Options instancefooter
- the banner to display at the end of the helppublic void printHelp(int width, java.lang.String cmdLineSyntax, java.lang.String header, Options options, java.lang.String footer, boolean autoUsage)
Print the help for options
with the specified
command line syntax. This method prints help information to
System.out.
width
- the number of characters to be displayed on each linecmdLineSyntax
- the syntax for this applicationheader
- the banner to display at the begining of the helpoptions
- the Options instancefooter
- the banner to display at the end of the helpautoUsage
- whether to print an automatically generated
usage statementpublic void printHelp(java.io.PrintWriter pw, int width, java.lang.String cmdLineSyntax, java.lang.String header, Options options, int leftPad, int descPad, java.lang.String footer)
Print the help for options
with the specified
command line syntax.
pw
- the writer to which the help will be writtenwidth
- the number of characters to be displayed on each linecmdLineSyntax
- the syntax for this applicationheader
- the banner to display at the begining of the helpoptions
- the Options instanceleftPad
- the number of characters of padding to be prefixed
to each linedescPad
- the number of characters of padding to be prefixed
to each description linefooter
- the banner to display at the end of the helppublic void printHelp(java.io.PrintWriter pw, int width, java.lang.String cmdLineSyntax, java.lang.String header, Options options, int leftPad, int descPad, java.lang.String footer, boolean autoUsage)
Print the help for options
with the specified
command line syntax.
pw
- the writer to which the help will be writtenwidth
- the number of characters to be displayed on each linecmdLineSyntax
- the syntax for this applicationheader
- the banner to display at the begining of the helpoptions
- the Options instanceleftPad
- the number of characters of padding to be prefixed
to each linedescPad
- the number of characters of padding to be prefixed
to each description linefooter
- the banner to display at the end of the helpautoUsage
- whether to print an automatically generated
usage statementpublic void printUsage(java.io.PrintWriter pw, int width, java.lang.String app, Options options)
Prints the usage statement for the specified application.
pw
- The PrintWriter to print the usage statementwidth
- The number of characters to display per lineapp
- The application nameoptions
- The command line Optionsprivate static void appendOptionGroup(java.lang.StringBuffer buff, OptionGroup group)
buff
- the StringBuffer to append togroup
- the group to appendappendOption(StringBuffer,Option,boolean)
private static void appendOption(java.lang.StringBuffer buff, Option option, boolean required)
buff
- the StringBuffer to append tooption
- the Option to appendrequired
- whether the Option is required or notpublic void printUsage(java.io.PrintWriter pw, int width, java.lang.String cmdLineSyntax)
Print the cmdLineSyntax to the specified writer, using the specified width.
pw
- The printWriter to write the help towidth
- The number of characters per line for the usage statement.cmdLineSyntax
- The usage statement.public void printOptions(java.io.PrintWriter pw, int width, Options options, int leftPad, int descPad)
Print the help for the specified Options to the specified writer, using the specified width, left padding and description padding.
pw
- The printWriter to write the help towidth
- The number of characters to display per lineoptions
- The command line OptionsleftPad
- the number of characters of padding to be prefixed
to each linedescPad
- the number of characters of padding to be prefixed
to each description linepublic void printWrapped(java.io.PrintWriter pw, int width, java.lang.String text)
Print the specified text to the specified PrintWriter.
pw
- The printWriter to write the help towidth
- The number of characters to display per linetext
- The text to be written to the PrintWriterpublic void printWrapped(java.io.PrintWriter pw, int width, int nextLineTabStop, java.lang.String text)
Print the specified text to the specified PrintWriter.
pw
- The printWriter to write the help towidth
- The number of characters to display per linenextLineTabStop
- The position on the next line for the first tab.text
- The text to be written to the PrintWriterprotected java.lang.StringBuffer renderOptions(java.lang.StringBuffer sb, int width, Options options, int leftPad, int descPad)
Render the specified Options and return the rendered Options in a StringBuffer.
sb
- The StringBuffer to place the rendered Options into.width
- The number of characters to display per lineoptions
- The command line OptionsleftPad
- the number of characters of padding to be prefixed
to each linedescPad
- the number of characters of padding to be prefixed
to each description lineprotected java.lang.StringBuffer renderWrappedText(java.lang.StringBuffer sb, int width, int nextLineTabStop, java.lang.String text)
Render the specified text and return the rendered Options in a StringBuffer.
sb
- The StringBuffer 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.protected int findWrapPos(java.lang.String text, int width, int startPos)
startPos
for the
text in text
with the column width width
.
The wrap point is the last postion before startPos+width having a
whitespace character (space, \n, \r).text
- The text being searched for the wrap positionwidth
- width of the wrapped textstartPos
- position from which to start the lookup whitespace
characterprotected java.lang.String createPadding(int len)
Return a String of padding of length len
.
len
- The length of the String of padding to create.protected java.lang.String rtrim(java.lang.String s)
Remove the trailing whitespace from the specified String.
s
- The String to remove the trailing padding from.