commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r544762 - in /jakarta/commons/proper/cli/branches/cli-1.0.x/src: java/org/apache/commons/cli/HelpFormatter.java test/org/apache/commons/cli/BugsTest.java test/org/apache/commons/cli/TestHelpFormatter.java
Date Wed, 06 Jun 2007 08:01:20 GMT
Author: bayard
Date: Wed Jun  6 01:01:19 2007
New Revision: 544762

URL: http://svn.apache.org/viewvc?view=rev&rev=544762
Log:
Applying Brian Egge's enhancement from CLI-131

Modified:
    jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java
    jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java
    jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java

Modified: jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java?view=diff&rev=544762&r1=544761&r2=544762
==============================================================================
--- jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java
(original)
+++ jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java
Wed Jun  6 01:01:19 2007
@@ -442,8 +442,10 @@
         // temp variable
         Option option;
 
+        List optList = new ArrayList(options.getOptions());
+        Collections.sort(optList, new OptionComparator());
         // iterate over the options
-        for (Iterator i = options.getOptions().iterator(); i.hasNext();)
+        for (Iterator i = optList.iterator(); i.hasNext();)
         {
             // get the next Option
             option = (Option) i.next();
@@ -503,8 +505,10 @@
             buff.append("[");
         }
 
+        List optList = new ArrayList(group.getOptions());
+        Collections.sort(optList, new OptionComparator());
         // for each option in the OptionGroup
-        for (Iterator i = group.getOptions().iterator(); i.hasNext();)
+        for (Iterator i = optList.iterator(); i.hasNext();)
         {
             // whether the option is required or not is handled at group level
             appendOption(buff, (Option) i.next(), true);

Modified: jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java?view=diff&rev=544762&r1=544761&r2=544762
==============================================================================
--- jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java
(original)
+++ jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java
Wed Jun  6 01:01:19 2007
@@ -466,8 +466,8 @@
         StringWriter out = new StringWriter();
         formatter.printHelp(new PrintWriter(out),80,"commandline","header",mOptions,2,2,"footer",true);
         assertEquals(
-                "usage: commandline [--config <arg>] [-r <arg>] [-a <arg>]
[-h] [-t] [-n] [-l"+EOL+
-                "       <arg>] [-s <arg>] [-v]"+EOL+
+                "usage: commandline [-a <arg>] [--config <arg>] [-h] [-l <arg>]
[-n] [-r <arg>]" + EOL +
+                "       [-s <arg>] [-t] [-v]" + EOL +
                 "header"+EOL+
                 "  -a,--age <arg>      Age (in days) of cache item before being recomputed"+EOL+
                 "     --config <arg>   Use the specified configuration file"+EOL+
@@ -527,7 +527,7 @@
         StringWriter out = new StringWriter();
         formatter.printHelp(new PrintWriter(out),80, "foobar", "", options, 2, 2, "", true);
         assertEquals(
-                "usage: foobar [-a] [-c] [--bbb]"+SEP+
+                "usage: foobar [-a] [--bbb] [-c]"+SEP+
                 "  -a,--aaa  aaaaaaa"+SEP+
                 "     --bbb  bbbbbbb"+SEP+
                 "  -c        ccccccc"+SEP

Modified: jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java?view=diff&rev=544762&r1=544761&r2=544762
==============================================================================
--- jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java
(original)
+++ jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java
Wed Jun  6 01:01:19 2007
@@ -27,9 +27,13 @@
  *
  * @author Slawek Zachcial
  * @author John Keyes ( john at integralsource.com )
+ * @author brianegge
  **/
 public class TestHelpFormatter extends TestCase
 {
+
+   private static final String EOL = System.getProperty("line.separator");
+
    public static void main( String[] args )
    {
       String[] testName = { TestHelpFormatter.class.getName() };
@@ -174,4 +178,23 @@
        assertEquals("simple auto usage", expected, out.toString().trim());
        out.reset();
    }
+
+    // This test ensures the options are properly sorted
+    // See https://issues.apache.org/jira/browse/CLI-131
+    public void testPrintUsage() {
+        Option optionA = new Option("a", "first");
+        Option optionB = new Option("b", "second");
+        Option optionC = new Option("c", "third");
+        Options opts = new Options();
+        opts.addOption(optionA);
+        opts.addOption(optionB);
+        opts.addOption(optionC);
+        HelpFormatter helpFormatter = new HelpFormatter();
+        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+        PrintWriter printWriter = new PrintWriter(bytesOut);
+        helpFormatter.printUsage(printWriter, 80, "app", opts);
+        printWriter.close();
+        assertEquals("usage: app [-a] [-b] [-c]" + EOL, bytesOut.toString());
+    }
+
 }



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