net.dpml.cli.util

Class HelpFormatter


public class HelpFormatter
extends java.lang.Object

Presents on screen help based on the application's Options
Version:
@PROJECT-VERSION@
Author:
@PUBLISHER-NAME@

Field Summary

static int
DEFAULT_DESCRIPTION_WIDTH
The default minimum description width.
static Set
DEFAULT_DISPLAY_USAGE_SETTINGS
The default DisplaySettings used to select the help lines in the main body of help
static Set
DEFAULT_FULL_USAGE_SETTINGS
The default DisplaySettings used to select the elements to display in the displayed line of full usage information.
static int
DEFAULT_FULL_WIDTH
The default screen width
static String
DEFAULT_GUTTER_CENTER
The default screen furniture right of screen
static String
DEFAULT_GUTTER_LEFT
The default screen furniture left of screen
static String
DEFAULT_GUTTER_RIGHT
The default screen furniture between columns
static Set
DEFAULT_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

Comparator
getComparator()
Return the comparator.
Set
getDisplaySettings()
Return the display settings.
String
getDivider()
Return the divider.
OptionException
getException()
Return the option exception
String
getFooter()
Return the footer text.
Set
getFullUsageSettings()
Return the full usage display settings.
Group
getGroup()
Return the group.
String
getGutterCenter()
Return the gutter center string.
String
getGutterLeft()
Return the gutter left string.
String
getGutterRight()
Return the gutter right string.
String
getHeader()
Return the header string.
Set
getLineUsageSettings()
Return the line usage settings.
int
getPageWidth()
Return the page width.
PrintWriter
getPrintWriter()
Return the print writer.
String
getShellCommand()
Return the shell command.
protected static void
pad(String text, int width, Writer writer)
Pad the supplied string.
void
print()
Prints the Option help.
void
printDivider()
Prints the m_divider text
void
printException()
Prints any error message.
void
printFooter()
Prints a m_footer string if necessary
void
printGutterLeft()
Prints the left gutter string
void
printGutterRight()
Prints the right gutter string
void
printHeader()
Prints a m_header string if necessary
void
printHelp()
Prints detailed help per option.
void
printUsage()
Prints a single line of usage information (wrapping if necessary)
protected void
printWrapped(String text)
Prints a string wrapped if necessary
void
setComparator(Comparator comparator)
The Comparator to use when sorting Options
void
setDisplaySettings(Set displaySettings)
The DisplaySettings used to select the help lines in the main body of help
void
setDivider(String divider)
Sets the string to use as a m_divider between sections of help
void
setException(OptionException exception)
Sets the exception to document
void
setFooter(String footer)
Sets the footer text of the help screen
void
setFullUsageSettings(Set fullUsageSettings)
The DisplaySettings used to select the elements to display in the displayed line of full usage information.
void
setGroup(Group group)
Sets the Group of Options to document
void
setHeader(String header)
Sets the header text of the help screen
void
setLineUsageSettings(Set lineUsageSettings)
Sets the DisplaySettings used to select elements in the per helpline usage strings.
void
setPrintWriter(PrintWriter out)
Set the print writer.
void
setShellCommand(String shellCommand)
Sets the command string used to invoke the application
protected static List
wrap(String text, int width)
Return a list of strings resulting from the wrapping of a supplied target string.

Field Details

DEFAULT_DESCRIPTION_WIDTH

public static final int DEFAULT_DESCRIPTION_WIDTH
The default minimum description width.
Field Value:
-1

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.

DEFAULT_FULL_WIDTH

public static final int DEFAULT_FULL_WIDTH
The default screen width
Field Value:
80

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

Constructor Details

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 Details

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)
            throws IOException
Pad the supplied string.
Parameters:
text - the text to pad
width - the padding width
writer - the writer

print

public void print()
            throws IOException
Prints the Option help.

printDivider

public void printDivider()
Prints the m_divider text

printException

public void printException()
            throws IOException
Prints any error message.

printFooter

public void printFooter()
            throws IOException
Prints a m_footer string if necessary

printGutterLeft

public void printGutterLeft()
Prints the left gutter string

printGutterRight

public void printGutterRight()
Prints the right gutter string

printHeader

public void printHeader()
            throws IOException
Prints a m_header string if necessary

printHelp

public void printHelp()
            throws IOException
Prints detailed help per option.

printUsage

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

printWrapped

protected void printWrapped(String text)
            throws IOException
Prints a string wrapped if necessary
Parameters:
text - the string to wrap

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

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

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

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