org.apache.commons.cli

Class HelpFormatter

public class HelpFormatter extends Object

A formatter of help messages for the current command line options

Author: Slawek Zachcial John Keyes (john at integralsource.com)

Nested Class Summary
static classHelpFormatter.StringBufferComparator
Field Summary
StringdefaultArgName
intdefaultDescPad
intdefaultLeftPad
StringdefaultLongOptPrefix
StringdefaultNewLine
StringdefaultOptPrefix
StringdefaultSyntaxPrefix
intdefaultWidth
static StringDEFAULT_ARG_NAME
static intDEFAULT_DESC_PAD
static intDEFAULT_LEFT_PAD
static StringDEFAULT_LONG_OPT_PREFIX
static StringDEFAULT_OPT_PREFIX
static StringDEFAULT_SYNTAX_PREFIX
static intDEFAULT_WIDTH
Constructor Summary
HelpFormatter()
Method Summary
protected StringcreatePadding(int len)
protected intfindWrapPos(String text, int width, int startPos)
Finds the next text wrap position after startPos for the text in sb with the column width width.
voidprintHelp(String cmdLineSyntax, Options options)
voidprintHelp(String cmdLineSyntax, Options options, boolean autoUsage)
voidprintHelp(String cmdLineSyntax, String header, Options options, String footer)
voidprintHelp(String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage)
voidprintHelp(int width, String cmdLineSyntax, String header, Options options, String footer)
voidprintHelp(int width, String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage)
voidprintHelp(PrintWriter pw, int width, String cmdLineSyntax, String header, Options options, int leftPad, int descPad, String footer)
voidprintHelp(PrintWriter pw, int width, String cmdLineSyntax, String header, Options options, int leftPad, int descPad, String footer, boolean autoUsage)
voidprintOptions(PrintWriter pw, int width, Options options, int leftPad, int descPad)
voidprintUsage(PrintWriter pw, int width, String app, Options options)

Prints the usage statement for the specified application.

voidprintUsage(PrintWriter pw, int width, String cmdLineSyntax)
voidprintWrapped(PrintWriter pw, int width, String text)
voidprintWrapped(PrintWriter pw, int width, int nextLineTabStop, String text)
protected StringBufferrenderOptions(StringBuffer sb, int width, Options options, int leftPad, int descPad)
protected StringBufferrenderWrappedText(StringBuffer sb, int width, int nextLineTabStop, String text)
protected Stringrtrim(String s)

Field Detail

defaultArgName

public String defaultArgName

defaultDescPad

public int defaultDescPad

defaultLeftPad

public int defaultLeftPad

defaultLongOptPrefix

public String defaultLongOptPrefix

defaultNewLine

public String defaultNewLine

defaultOptPrefix

public String defaultOptPrefix

defaultSyntaxPrefix

public String defaultSyntaxPrefix

defaultWidth

public int defaultWidth

DEFAULT_ARG_NAME

public static final String DEFAULT_ARG_NAME

DEFAULT_DESC_PAD

public static final int DEFAULT_DESC_PAD

DEFAULT_LEFT_PAD

public static final int DEFAULT_LEFT_PAD

DEFAULT_LONG_OPT_PREFIX

public static final String DEFAULT_LONG_OPT_PREFIX

DEFAULT_OPT_PREFIX

public static final String DEFAULT_OPT_PREFIX

DEFAULT_SYNTAX_PREFIX

public static final String DEFAULT_SYNTAX_PREFIX

DEFAULT_WIDTH

public static final int DEFAULT_WIDTH

Constructor Detail

HelpFormatter

public HelpFormatter()

Method Detail

createPadding

protected String createPadding(int len)

findWrapPos

protected int findWrapPos(String text, int width, int startPos)
Finds the next text wrap position after startPos for the text in sb with the column width width. The wrap point is the last postion before startPos+width having a whitespace character (space, \n, \r).

Parameters: sb text to be analyzed width width of the wrapped text startPos position from which to start the lookup whitespace character

Returns: postion on which the text must be wrapped or -1 if the wrap position is at the end of the text

printHelp

public void printHelp(String cmdLineSyntax, Options options)

printHelp

public void printHelp(String cmdLineSyntax, Options options, boolean autoUsage)

printHelp

public void printHelp(String cmdLineSyntax, String header, Options options, String footer)

printHelp

public void printHelp(String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage)

printHelp

public void printHelp(int width, String cmdLineSyntax, String header, Options options, String footer)

printHelp

public void printHelp(int width, String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage)

printHelp

public void printHelp(PrintWriter pw, int width, String cmdLineSyntax, String header, Options options, int leftPad, int descPad, String footer)

printHelp

public void printHelp(PrintWriter pw, int width, String cmdLineSyntax, String header, Options options, int leftPad, int descPad, String footer, boolean autoUsage)

printOptions

public void printOptions(PrintWriter pw, int width, Options options, int leftPad, int descPad)

printUsage

public void printUsage(PrintWriter pw, int width, String app, Options options)

Prints the usage statement for the specified application.

Parameters: pw The PrintWriter to print the usage statement width ?? appName The application name options The command line Options

printUsage

public void printUsage(PrintWriter pw, int width, String cmdLineSyntax)

printWrapped

public void printWrapped(PrintWriter pw, int width, String text)

printWrapped

public void printWrapped(PrintWriter pw, int width, int nextLineTabStop, String text)

renderOptions

protected StringBuffer renderOptions(StringBuffer sb, int width, Options options, int leftPad, int descPad)

renderWrappedText

protected StringBuffer renderWrappedText(StringBuffer sb, int width, int nextLineTabStop, String text)

rtrim

protected String rtrim(String s)