commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roxspr...@apache.org
Subject cvs commit: jakarta-commons/cli/src/java/org/apache/commons/cli2/util HelpFormatter.java
Date Wed, 14 Apr 2004 18:25:44 GMT
roxspring    2004/04/14 11:25:44

  Modified:    cli/src/test/org/apache/commons/cli2/util Tag:
                        RESEARCH_CLI_2_ROXSPRING HelpFormatterTest.java
               cli/src/java/org/apache/commons/cli2/util Tag:
                        RESEARCH_CLI_2_ROXSPRING HelpFormatter.java
  Log:
  HelpFormatter print methods now use the member PrintWriter rather than a parameter
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.3   +14 -8     jakarta-commons/cli/src/test/org/apache/commons/cli2/util/Attic/HelpFormatterTest.java
  
  Index: HelpFormatterTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli2/util/Attic/HelpFormatterTest.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- HelpFormatterTest.java	1 Apr 2004 21:13:36 -0000	1.1.2.2
  +++ HelpFormatterTest.java	14 Apr 2004 18:25:43 -0000	1.1.2.3
  @@ -136,8 +136,8 @@
   
       public void testPrintHelp() throws IOException {
           final StringWriter writer = new StringWriter();
  -        helpFormatter.printHelp(new PrintWriter(writer));
  -        //System.out.println(writer);
  +        helpFormatter.setPrintWriter(new PrintWriter(writer));
  +        helpFormatter.printHelp();
           final BufferedReader reader =
               new BufferedReader(new StringReader(writer.toString()));
           assertEquals(
  @@ -172,8 +172,9 @@
   
       public void testPrintHelp_WithException() throws IOException {
           final StringWriter writer = new StringWriter();
  +        helpFormatter.setPrintWriter(new PrintWriter(writer));
           helpFormatter.setException(new OptionException(verbose));
  -        helpFormatter.printHelp(new PrintWriter(writer));
  +        helpFormatter.printHelp();
           //System.out.println(writer);
           final BufferedReader reader =
               new BufferedReader(new StringReader(writer.toString()));
  @@ -191,8 +192,9 @@
   
       public void testPrintException() throws IOException {
           final StringWriter writer = new StringWriter();
  +        helpFormatter.setPrintWriter(new PrintWriter(writer));
           helpFormatter.setException(new OptionException(verbose, "cli.error.missing.option"));
  -        helpFormatter.printException(new PrintWriter(writer));
  +        helpFormatter.printException();
           //System.out.println(writer);
           final BufferedReader reader =
               new BufferedReader(new StringReader(writer.toString()));
  @@ -207,7 +209,8 @@
   
       public void testPrintUsage() throws IOException {
           final StringWriter writer = new StringWriter();
  -        helpFormatter.printUsage(new PrintWriter(writer));
  +        helpFormatter.setPrintWriter(new PrintWriter(writer));
  +        helpFormatter.printUsage();
           final BufferedReader reader =
               new BufferedReader(new StringReader(writer.toString()));
           assertEquals(
  @@ -227,7 +230,8 @@
   
       public void testPrintHeader() throws IOException {
           final StringWriter writer = new StringWriter();
  -        helpFormatter.printHeader(new PrintWriter(writer));
  +        helpFormatter.setPrintWriter(new PrintWriter(writer));
  +        helpFormatter.printHeader();
           final BufferedReader reader =
               new BufferedReader(new StringReader(writer.toString()));
           assertEquals(
  @@ -241,7 +245,8 @@
   
       public void testPrintFooter() throws IOException {
           final StringWriter writer = new StringWriter();
  -        helpFormatter.printFooter(new PrintWriter(writer));
  +        helpFormatter.setPrintWriter(new PrintWriter(writer));
  +        helpFormatter.printFooter();
           final BufferedReader reader =
               new BufferedReader(new StringReader(writer.toString()));
           assertEquals(
  @@ -258,7 +263,8 @@
   
       public void testPrintDivider() throws IOException {
           final StringWriter writer = new StringWriter();
  -        helpFormatter.printDivider(new PrintWriter(writer));
  +        helpFormatter.setPrintWriter(new PrintWriter(writer));
  +        helpFormatter.printDivider();
           final BufferedReader reader =
               new BufferedReader(new StringReader(writer.toString()));
           assertEquals(
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +158 -59   jakarta-commons/cli/src/java/org/apache/commons/cli2/util/Attic/HelpFormatter.java
  
  Index: HelpFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/util/Attic/HelpFormatter.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- HelpFormatter.java	31 Mar 2004 00:50:45 -0000	1.1.2.1
  +++ HelpFormatter.java	14 Apr 2004 18:25:43 -0000	1.1.2.2
  @@ -32,16 +32,51 @@
   import org.apache.commons.cli2.Option;
   import org.apache.commons.cli2.OptionException;
   
  +/**
  + * Presents on screen help based on the application's Options
  + */
   public class HelpFormatter {
   
  +    /**
  +     * The default screen width
  +     */
       public static final int DEFAULT_FULL_WIDTH = 80;
   
  +    /**
  +     * The default screen furniture left of screen
  +     */
       public static final String DEFAULT_GUTTER_LEFT = "";
  +    
  +    /**
  +     * The default screen furniture right of screen
  +     */
       public static final String DEFAULT_GUTTER_CENTER = "    ";
  +    
  +    /**
  +     * The default screen furniture between columns
  +     */
       public static final String DEFAULT_GUTTER_RIGHT = "";
   
  +    /**
  +     * The default DisplaySettings used to select the elements to display in the
  +     * displayed line of full usage information.
  +     * 
  +     * @see DisplaySetting
  +     */
       public static final Set DEFAULT_FULL_USAGE_SETTINGS;
  +    
  +    /**
  +     * The default DisplaySettings used to select the elements of usage per help 
  +     * line in the main body of help
  +     * 
  +     * @see DisplaySetting
  +     */
       public static final Set DEFAULT_LINE_USAGE_SETTINGS;
  +    
  +    /**
  +     * The default DisplaySettings used to select the help lines in the main
  +     * body of help 
  +     */
       public static final Set DEFAULT_DISPLAY_USAGE_SETTINGS;
   
       static {
  @@ -84,6 +119,9 @@
   
       private final int pageWidth;
   
  +    /**
  +     * Creates a new HelpFormatter using the defaults
  +     */
       public HelpFormatter() {
           this(
               DEFAULT_GUTTER_LEFT,
  @@ -92,6 +130,13 @@
               DEFAULT_FULL_WIDTH);
       }
   
  +    /**
  +     * Creates a new HelpFormatter using the specified parameters
  +     * @param gutterLeft the string marking left of screen
  +     * @param gutterCenter the string marking center of screen
  +     * @param gutterRight the string marking right of screen
  +     * @param fullWidth the width of the screen
  +     */
       public HelpFormatter(
           final String gutterLeft,
           final String gutterCenter,
  @@ -125,25 +170,37 @@
                       + "Supply shorter gutters or more width.");
           }
       }
  -
  +    
  +    /**
  +     * Prints the Option help.
  +     * @throws IOException if an error occurs
  +     */
       public void print() throws IOException {
  -        printHeader(out);
  -        printException(out);
  -        printUsage(out);
  -        printHelp(out);
  -        printFooter(out);
  +        printHeader();
  +        printException();
  +        printUsage();
  +        printHelp();
  +        printFooter();
           out.flush();
       }
   
  -    public void printException(final PrintWriter out) throws IOException {
  +    /**
  +     * Prints any error message. 
  +     * @throws IOException if an error occurs
  +     */
  +    public void printException() throws IOException {
           if (exception != null) {
  -            printDivider(out);
  -            printWrapped(out, exception.getMessage());
  +            printDivider();
  +            printWrapped(exception.getMessage());
           }
       }
   
  -    public void printHelp(final PrintWriter out) throws IOException {
  -        printDivider(out);
  +    /**
  +     * Prints detailed help per option. 
  +     * @throws IOException if an error occurs
  +     */
  +    public void printHelp() throws IOException {
  +        printDivider();
   
           final Option option;
           if (exception != null && exception.getOption() != null) {
  @@ -172,73 +229,99 @@
                   wrap(helpLine.getDescription(), descriptionWidth);
               final Iterator j = descriptionLines.iterator();
   
  -            printGutterLeft(out);
  +            printGutterLeft();
               pad(helpLine.usage(lineUsageSettings, comparator), usageWidth, out);
               out.print(gutterCenter);
               pad((String)j.next(), descriptionWidth, out);
  -            printGutterRight(out);
  +            printGutterRight();
               out.println();
   
               while (j.hasNext()) {
  -                printGutterLeft(out);
  +                printGutterLeft();
                   //pad(helpLine.getUsage(),usageWidth,out);
                   out.print(blankBuffer);
                   out.print(gutterCenter);
                   pad((String)j.next(), descriptionWidth, out);
  -                printGutterRight(out);
  +                printGutterRight();
                   out.println();
               }
           }
  -        printDivider(out);
  +        printDivider();
       }
   
  -    public void printUsage(final PrintWriter out) throws IOException {
  -        printDivider(out);
  +    /**
  +     * Prints a single line of usage information (wrapping if necessary) 
  +     * @throws IOException if an error occurs
  +     */
  +    public void printUsage() throws IOException {
  +        printDivider();
           final StringBuffer buffer = new StringBuffer("Usage:\n");
           buffer.append(shellCommand).append(' ');
           group.appendUsage(buffer, fullUsageSettings, comparator, " ");
  -        printWrapped(out, buffer.toString());
  +        printWrapped(buffer.toString());
       }
   
  -    public void printHeader(final PrintWriter out) throws IOException {
  +    /**
  +     * Prints a header string if necessary 
  +     * @throws IOException if an error occurs
  +     */
  +    public void printHeader() throws IOException {
           if (header != null) {
  -            printDivider(out);
  -            printWrapped(out, header);
  +            printDivider();
  +            printWrapped(header);
           }
       }
   
  -    public void printFooter(final PrintWriter out) throws IOException {
  +    /**
  +     * Prints a footer string if necessary 
  +     * @throws IOException if an error occurs
  +     */
  +    public void printFooter() throws IOException {
           if (footer != null) {
  -            printWrapped(out, footer);
  -            printDivider(out);
  +            printWrapped(footer);
  +            printDivider();
           }
       }
   
  -    public void printWrapped(final PrintWriter out, final String text)
  +    /**
  +     * Prints a string wrapped if necessary
  +     * @param text the string to wrap 
  +     * @throws IOException if an error occurs
  +     */
  +    protected void printWrapped(final String text)
           throws IOException {
           for (final Iterator i = wrap(text, pageWidth).iterator();
               i.hasNext();
               ) {
  -            printGutterLeft(out);
  +            printGutterLeft();
               pad((String)i.next(), pageWidth, out);
  -            printGutterRight(out);
  +            printGutterRight();
               out.println();
           }
       }
   
  -    public void printGutterLeft(final PrintWriter out) {
  +    /**
  +     * Prints the left gutter string 
  +     */
  +    public void printGutterLeft() {
           if (gutterLeft != null) {
               out.print(gutterLeft);
           }
       }
   
  -    public void printGutterRight(final PrintWriter out) {
  +    /**
  +     * Prints the right gutter string 
  +     */
  +    public void printGutterRight() {
           if (gutterRight != null) {
               out.print(gutterRight);
           }
       }
   
  -    public void printDivider(final PrintWriter out) {
  +    /**
  +     * Prints the divider text
  +     */
  +    public void printDivider() {
           if (divider != null) {
               out.println(divider);
           }
  @@ -321,41 +404,52 @@
       }
   
       /**
  -     * @param comparator
  +     * The Comparator to use when sorting Options
  +     * @param comparator Comparator to use when sorting Options
        */
       public void setComparator(Comparator comparator) {
           this.comparator = comparator;
       }
  -
  +    
       /**
  -     * @param displaySettings
  +     * The DisplaySettings used to select the help lines in the main body of
  +     * help
  +     * 
  +     * @param displaySettings the settings to use
  +     * @see DisplaySetting
        */
       public void setDisplaySettings(Set displaySettings) {
           this.displaySettings = displaySettings;
       }
   
       /**
  -     * @param divider
  +     * Sets the string to use as a divider between sections of help
  +     * @param divider the dividing string
        */
       public void setDivider(String divider) {
           this.divider = divider;
       }
  -
  +    
       /**
  -     * @param exception
  +     * Sets the exception to document
  +     * @param exception the exception that occured
        */
       public void setException(OptionException exception) {
           this.exception = exception;
       }
   
       /**
  -     * @param footer
  +     * Sets the footer text of the help screen
  +     * @param footer the footer text
        */
       public void setFooter(String footer) {
           this.footer = footer;
       }
   
       /**
  +     * The DisplaySettings used to select the elements to display in the
  +     * displayed line of full usage information. 
  +     * @see DisplaySetting
        * @param fullUsageSettings
        */
       public void setFullUsageSettings(Set fullUsageSettings) {
  @@ -363,141 +457,146 @@
       }
   
       /**
  -     * @param group
  +     * Sets the Group of Options to document
  +     * @param group the options to document
        */
       public void setGroup(Group group) {
           this.group = group;
       }
   
       /**
  -     * @param header
  +     * Sets the footer text of the help screen
  +     * @param header the footer text
        */
       public void setHeader(String header) {
           this.header = header;
       }
   
       /**
  -     * @param lineUsageSettings
  +     * Sets the DisplaySettings used to select elements in the per helpline 
  +     * usage strings.
  +     * @see DisplaySetting
  +     * @param lineUsageSettings the DisplaySettings to use
        */
       public void setLineUsageSettings(Set lineUsageSettings) {
           this.lineUsageSettings = lineUsageSettings;
       }
   
       /**
  -     * @param shellCommand
  +     * Sets the command string used to invoke the application
  +     * @param shellCommand the invokation command
        */
       public void setShellCommand(String shellCommand) {
           this.shellCommand = shellCommand;
       }
   
       /**
  -     * @return
  +     * @return the Comparator used to sort the Group
        */
       public Comparator getComparator() {
           return comparator;
       }
   
       /**
  -     * @return
  +     * @return the DisplaySettings used to select HelpLines
        */
       public Set getDisplaySettings() {
           return displaySettings;
       }
   
       /**
  -     * @return
  +     * @return the String used as a horizontal section divider
        */
       public String getDivider() {
           return divider;
       }
   
       /**
  -     * @return
  +     * @return the Exception being documented by this HelpFormatter
        */
       public OptionException getException() {
           return exception;
       }
   
       /**
  -     * @return
  +     * @return the help screen footer text
        */
       public String getFooter() {
           return footer;
       }
   
       /**
  -     * @return
  +     * @return the DisplaySettings used in the full usage string
        */
       public Set getFullUsageSettings() {
           return fullUsageSettings;
       }
   
       /**
  -     * @return
  +     * @return the group documented by this HelpFormatter
        */
       public Group getGroup() {
           return group;
       }
   
       /**
  -     * @return
  +     * @return the String used as the central gutter
        */
       public String getGutterCenter() {
           return gutterCenter;
       }
   
       /**
  -     * @return
  +     * @return the String used as the left gutter
        */
       public String getGutterLeft() {
           return gutterLeft;
       }
   
       /**
  -     * @return
  +     * @return the String used as the right gutter
        */
       public String getGutterRight() {
           return gutterRight;
       }
   
       /**
  -     * @return
  +     * @return the help screen header text
        */
       public String getHeader() {
           return header;
       }
   
       /**
  -     * @return
  +     * @return the DisplaySettings used in the per help line usage strings
        */
       public Set getLineUsageSettings() {
           return lineUsageSettings;
       }
   
       /**
  -     * @return
  +     * @return the width of the screen in characters
        */
       public int getPageWidth() {
           return pageWidth;
       }
   
       /**
  -     * @return
  +     * @return the command used to execute the application  
        */
       public String getShellCommand() {
           return shellCommand;
       }
   
       /**
  -     * @param out
  -     *            The out to set.
  +     * @param out the PrintWriter to write to
        */
       public void setPrintWriter(PrintWriter out) {
           this.out = out;
       }
   
       /**
  -     * @return Returns the out.
  +     * @return the PrintWriter that will be written to
        */
       public PrintWriter getPrintWriter() {
           return out;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message