commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r661634 - in /commons/proper/cli/branches/cli-1.x/src: java/org/apache/commons/cli/HelpFormatter.java test/org/apache/commons/cli/HelpFormatterTest.java
Date Fri, 30 May 2008 10:22:49 GMT
Author: ebourg
Date: Fri May 30 03:22:49 2008
New Revision: 661634

URL: http://svn.apache.org/viewvc?rev=661634&view=rev
Log:
Added a formatter test for options with a null or empty named argument

Modified:
    commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java

Modified: commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java?rev=661634&r1=661633&r2=661634&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java
(original)
+++ commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/HelpFormatter.java
Fri May 30 03:22:49 2008
@@ -629,7 +629,7 @@
         }
 
         // if the Option has a value
-        if (option.hasArg() && (option.getArgName() != null))
+        if (option.hasArg() && option.hasArgName())
         {
             buff.append(" <").append(option.getArgName()).append(">");
         }

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java?rev=661634&r1=661633&r2=661634&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java
(original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/HelpFormatterTest.java
Fri May 30 03:22:49 2008
@@ -257,4 +257,20 @@
         assertEquals("usage: app -a | -b | -c" + EOL, out.toString());
     }
 
+    public void testPrintOptionWithEmptyArgNameUsage() {
+        Option option = new Option("f", true, null);
+        option.setArgName("");
+        option.setRequired(true);
+
+        Options options = new Options();
+        options.addOption(option);
+
+        StringWriter out = new StringWriter();
+
+        HelpFormatter formatter = new HelpFormatter();
+        formatter.printUsage(new PrintWriter(out), 80, "app", options);
+
+        assertEquals("usage: app -f" + EOL, out.toString());
+    }
+
 }



Mime
View raw message