org.apache.commons.cli2.util
Class HelpFormatter

java.lang.Object
  extended by org.apache.commons.cli2.util.HelpFormatter

public class HelpFormatter
extends Object

Presents on screen help based on the application's Options


Field Summary
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
 
Method Summary
 Comparator getComparator()
           
 Set getDisplaySettings()
           
 String getDivider()
           
 OptionException getException()
           
 String getFooter()
           
 Set getFullUsageSettings()
           
 Group getGroup()
           
 String getGutterCenter()
           
 String getGutterLeft()
           
 String getGutterRight()
           
 String getHeader()
           
 Set getLineUsageSettings()
           
 int getPageWidth()
           
 PrintWriter getPrintWriter()
           
 String getShellCommand()
           
protected static void pad(String text, int width, PrintWriter writer)
           
 void print()
          Prints the Option help.
 void printDivider()
          Prints the divider text
 void printException()
          Prints any error message.
 void printFooter()
          Prints a footer string if necessary
 void printGutterLeft()
          Prints the left gutter string
 void printGutterRight()
          Prints the right gutter string
 void printHeader()
          Prints a header string if necessary
 void printHelp()
          Prints detailed help per option.
 void printUsage()
          Prints a single line of usage information (wrapping if necessary)
 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 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 footer 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)
           
 void setShellCommand(String shellCommand)
          Sets the command string used to invoke the application
protected static List wrap(String text, int width)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FULL_WIDTH

public static final int DEFAULT_FULL_WIDTH
The default screen width

See Also:
Constant Field Values

DEFAULT_GUTTER_LEFT

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

See Also:
Constant Field Values

DEFAULT_GUTTER_CENTER

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

See Also:
Constant Field Values

DEFAULT_GUTTER_RIGHT

public static final String DEFAULT_GUTTER_RIGHT
The default screen furniture between columns

See Also:
Constant Field Values

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_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

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

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
Method Detail

print

public void print()
Prints the Option help.


printException

public void printException()
Prints any error message.


printHelp

public void printHelp()
Prints detailed help per option.


printUsage

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


printHeader

public void printHeader()
Prints a header string if necessary


printFooter

public void printFooter()
Prints a footer string if necessary


printWrapped

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

Parameters:
text - the string to wrap

printGutterLeft

public void printGutterLeft()
Prints the left gutter string


printGutterRight

public void printGutterRight()
Prints the right gutter string


printDivider

public void printDivider()
Prints the divider text


pad

protected static void pad(String text,
                          int width,
                          PrintWriter writer)

wrap

protected static List wrap(String text,
                           int width)

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 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 -
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 footer text of the help screen

Parameters:
header - the 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

setShellCommand

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

Parameters:
shellCommand - the invokation command

getComparator

public Comparator getComparator()
Returns:
the Comparator used to sort the Group

getDisplaySettings

public Set getDisplaySettings()
Returns:
the DisplaySettings used to select HelpLines

getDivider

public String getDivider()
Returns:
the String used as a horizontal section divider

getException

public OptionException getException()
Returns:
the Exception being documented by this HelpFormatter

getFooter

public String getFooter()
Returns:
the help screen footer text

getFullUsageSettings

public Set getFullUsageSettings()
Returns:
the DisplaySettings used in the full usage string

getGroup

public Group getGroup()
Returns:
the group documented by this HelpFormatter

getGutterCenter

public String getGutterCenter()
Returns:
the String used as the central gutter

getGutterLeft

public String getGutterLeft()
Returns:
the String used as the left gutter

getGutterRight

public String getGutterRight()
Returns:
the String used as the right gutter

getHeader

public String getHeader()
Returns:
the help screen header text

getLineUsageSettings

public Set getLineUsageSettings()
Returns:
the DisplaySettings used in the per help line usage strings

getPageWidth

public int getPageWidth()
Returns:
the width of the screen in characters

getShellCommand

public String getShellCommand()
Returns:
the command used to execute the application

setPrintWriter

public void setPrintWriter(PrintWriter out)
Parameters:
out - the PrintWriter to write to

getPrintWriter

public PrintWriter getPrintWriter()
Returns:
the PrintWriter that will be written to


Copyright © 2002-2010 Apache Software Foundation. All Rights Reserved.