net.dpml.cli.util

Class HelpFormatter

public class HelpFormatter extends Object

Presents on screen help based on the application's Options

Version: @PROJECT-VERSION@

Author: @PUBLISHER-NAME@

Field Summary
static intDEFAULT_DESCRIPTION_WIDTH
The default minimum description width.
static SetDEFAULT_DISPLAY_USAGE_SETTINGS
The default DisplaySettings used to select the help lines in the main body of help
static SetDEFAULT_FULL_USAGE_SETTINGS
The default DisplaySettings used to select the elements to display in the displayed line of full usage information.
static intDEFAULT_FULL_WIDTH
The default screen width
static StringDEFAULT_GUTTER_CENTER
The default screen furniture right of screen
static StringDEFAULT_GUTTER_LEFT
The default screen furniture left of screen
static StringDEFAULT_GUTTER_RIGHT
The default screen furniture between columns
static SetDEFAULT_LINE_USAGE_SETTINGS
The default DisplaySettings used to select the elements of usage per help line in the main body of help
Constructor Summary
HelpFormatter()
Creates a new HelpFormatter using the defaults
HelpFormatter(String gutterLeft, String gutterCenter, String gutterRight, int fullWidth)
Creates a new HelpFormatter using the specified parameters
HelpFormatter(String gutterLeft, String gutterCenter, String gutterRight, int fullWidth, int descriptionWidth)
Creates a new HelpFormatter using the specified parameters
Method Summary
ComparatorgetComparator()
Return the comparator.
SetgetDisplaySettings()
Return the display settings.
StringgetDivider()
Return the divider.
OptionExceptiongetException()
Return the option exception
StringgetFooter()
Return the footer text.
SetgetFullUsageSettings()
Return the full usage display settings.
GroupgetGroup()
Return the group.
StringgetGutterCenter()
Return the gutter center string.
StringgetGutterLeft()
Return the gutter left string.
StringgetGutterRight()
Return the gutter right string.
StringgetHeader()
Return the header string.
SetgetLineUsageSettings()
Return the line usage settings.
intgetPageWidth()
Return the page width.
PrintWritergetPrintWriter()
Return the print writer.
StringgetShellCommand()
Return the shell command.
protected static voidpad(String text, int width, Writer writer)
Pad the supplied string.
voidprint()
Prints the Option help.
voidprintDivider()
Prints the m_divider text
voidprintException()
Prints any error message.
voidprintFooter()
Prints a m_footer string if necessary
voidprintGutterLeft()
Prints the left gutter string
voidprintGutterRight()
Prints the right gutter string
voidprintHeader()
Prints a m_header string if necessary
voidprintHelp()
Prints detailed help per option.
voidprintUsage()
Prints a single line of usage information (wrapping if necessary)
protected voidprintWrapped(String text)
Prints a string wrapped if necessary
voidsetComparator(Comparator comparator)
The Comparator to use when sorting Options
voidsetDisplaySettings(Set displaySettings)
The DisplaySettings used to select the help lines in the main body of help
voidsetDivider(String divider)
Sets the string to use as a m_divider between sections of help
voidsetException(OptionException exception)
Sets the exception to document
voidsetFooter(String footer)
Sets the footer text of the help screen
voidsetFullUsageSettings(Set fullUsageSettings)
The DisplaySettings used to select the elements to display in the displayed line of full usage information.
voidsetGroup(Group group)
Sets the Group of Options to document
voidsetHeader(String header)
Sets the header text of the help screen
voidsetLineUsageSettings(Set lineUsageSettings)
Sets the DisplaySettings used to select elements in the per helpline usage strings.
voidsetPrintWriter(PrintWriter out)
Set the print writer.
voidsetShellCommand(String shellCommand)
Sets the command string used to invoke the application
protected static Listwrap(String text, int width)
Return a list of strings resulting from the wrapping of a supplied target string.

Field Detail

DEFAULT_DESCRIPTION_WIDTH

public static final int DEFAULT_DESCRIPTION_WIDTH
The default minimum description width.

DEFAULT_DISPLAY_USAGE_SETTINGS

public static final Set DEFAULT_DISPLAY_USAGE_SETTINGS
The default DisplaySettings used to select the help lines in the main body of help

DEFAULT_FULL_USAGE_SETTINGS

public static final Set DEFAULT_FULL_USAGE_SETTINGS
The default DisplaySettings used to select the elements to display in the displayed line of full usage information.

See Also: DisplaySetting

DEFAULT_FULL_WIDTH

public static final int DEFAULT_FULL_WIDTH
The default screen width

DEFAULT_GUTTER_CENTER

public static final String DEFAULT_GUTTER_CENTER
The default screen furniture right of screen

DEFAULT_GUTTER_LEFT

public static final String DEFAULT_GUTTER_LEFT
The default screen furniture left of screen

DEFAULT_GUTTER_RIGHT

public static final String DEFAULT_GUTTER_RIGHT
The default screen furniture between columns

DEFAULT_LINE_USAGE_SETTINGS

public static final Set DEFAULT_LINE_USAGE_SETTINGS
The default DisplaySettings used to select the elements of usage per help line in the main body of help

See Also: DisplaySetting

Constructor Detail

HelpFormatter

public HelpFormatter()
Creates a new HelpFormatter using the defaults

HelpFormatter

public HelpFormatter(String gutterLeft, String gutterCenter, String gutterRight, int fullWidth)
Creates a new HelpFormatter using the specified parameters

Parameters: gutterLeft the string marking left of screen gutterCenter the string marking center of screen gutterRight the string marking right of screen fullWidth the width of the screen

HelpFormatter

public HelpFormatter(String gutterLeft, String gutterCenter, String gutterRight, int fullWidth, int descriptionWidth)
Creates a new HelpFormatter using the specified parameters

Parameters: gutterLeft the string marking left of screen gutterCenter the string marking center of screen gutterRight the string marking right of screen fullWidth the width of the screen descriptionWidth the minimum description width

Method Detail

getComparator

public Comparator getComparator()
Return the comparator.

Returns: the Comparator used to sort the Group

getDisplaySettings

public Set getDisplaySettings()
Return the display settings.

Returns: the DisplaySettings used to select HelpLines

getDivider

public String getDivider()
Return the divider.

Returns: the String used as a horizontal section m_divider

getException

public OptionException getException()
Return the option exception

Returns: the Exception being documented by this HelpFormatter

getFooter

public String getFooter()
Return the footer text.

Returns: the help screen footer text

getFullUsageSettings

public Set getFullUsageSettings()
Return the full usage display settings.

Returns: the DisplaySettings used in the full usage string

getGroup

public Group getGroup()
Return the group.

Returns: the group documented by this HelpFormatter

getGutterCenter

public String getGutterCenter()
Return the gutter center string.

Returns: the String used as the central gutter

getGutterLeft

public String getGutterLeft()
Return the gutter left string.

Returns: the String used as the left gutter

getGutterRight

public String getGutterRight()
Return the gutter right string.

Returns: the String used as the right gutter

getHeader

public String getHeader()
Return the header string.

Returns: the help screen header text

getLineUsageSettings

public Set getLineUsageSettings()
Return the line usage settings.

Returns: the DisplaySettings used in the per help line usage strings

getPageWidth

public int getPageWidth()
Return the page width.

Returns: the width of the screen in characters

getPrintWriter

public PrintWriter getPrintWriter()
Return the print writer.

Returns: the PrintWriter that will be written to

getShellCommand

public String getShellCommand()
Return the shell command.

Returns: the command used to execute the application

pad

protected static void pad(String text, int width, Writer writer)
Pad the supplied string.

Parameters: text the text to pad width the padding width writer the writer

Throws: IOException if an I/O error occurs

print

public void print()
Prints the Option help.

Throws: IOException if an error occurs

printDivider

public void printDivider()
Prints the m_divider text

printException

public void printException()
Prints any error message.

Throws: IOException if an error occurs

printFooter

public void printFooter()
Prints a m_footer string if necessary

Throws: IOException if an error occurs

printGutterLeft

public void printGutterLeft()
Prints the left gutter string

printGutterRight

public void printGutterRight()
Prints the right gutter string

printHeader

public void printHeader()
Prints a m_header string if necessary

Throws: IOException if an error occurs

printHelp

public void printHelp()
Prints detailed help per option.

Throws: IOException if an error occurs

printUsage

public void printUsage()
Prints a single line of usage information (wrapping if necessary)

Throws: IOException if an error occurs

printWrapped

protected void printWrapped(String text)
Prints a string wrapped if necessary

Parameters: text the string to wrap

Throws: IOException if an error occurs

setComparator

public void setComparator(Comparator comparator)
The Comparator to use when sorting Options

Parameters: comparator Comparator to use when sorting Options

setDisplaySettings

public void setDisplaySettings(Set displaySettings)
The DisplaySettings used to select the help lines in the main body of help

Parameters: displaySettings the settings to use

See Also: DisplaySetting

setDivider

public void setDivider(String divider)
Sets the string to use as a m_divider between sections of help

Parameters: divider the dividing string

setException

public void setException(OptionException exception)
Sets the exception to document

Parameters: exception the exception that occured

setFooter

public void setFooter(String footer)
Sets the footer text of the help screen

Parameters: footer the footer text

setFullUsageSettings

public void setFullUsageSettings(Set fullUsageSettings)
The DisplaySettings used to select the elements to display in the displayed line of full usage information.

Parameters: fullUsageSettings the full usage settings

See Also: DisplaySetting

setGroup

public void setGroup(Group group)
Sets the Group of Options to document

Parameters: group the options to document

setHeader

public void setHeader(String header)
Sets the header text of the help screen

Parameters: header the m_footer text

setLineUsageSettings

public void setLineUsageSettings(Set lineUsageSettings)
Sets the DisplaySettings used to select elements in the per helpline usage strings.

Parameters: lineUsageSettings the DisplaySettings to use

See Also: DisplaySetting

setPrintWriter

public void setPrintWriter(PrintWriter out)
Set the print writer.

Parameters: out the PrintWriter to write to

setShellCommand

public void setShellCommand(String shellCommand)
Sets the command string used to invoke the application

Parameters: shellCommand the invocation command

wrap

protected static List wrap(String text, int width)
Return a list of strings resulting from the wrapping of a supplied target string.

Parameters: text the target string to wrap width the wrappping width

Returns: the list of wrapped fragments