You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2008/07/28 10:43:29 UTC

svn commit: r680289 - in /commons/proper/cli/branches/cli-1.x/src: java/org/apache/commons/cli/PosixParser.java test/org/apache/commons/cli/PosixParserTest.java

Author: ebourg
Date: Mon Jul 28 01:43:28 2008
New Revision: 680289

URL: http://svn.apache.org/viewvc?rev=680289&view=rev
Log:
Fixed the handling of unrecognized options starting with '-' by PosixParser (CLI-164) (stopAtNonOption=false case)

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

Modified: commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java?rev=680289&r1=680288&r2=680289&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/java/org/apache/commons/cli/PosixParser.java Mon Jul 28 01:43:28 2008
@@ -229,13 +229,13 @@
         if (options.hasOption(token))
         {
             currentOption = options.getOption(token);
-            tokens.add(token);
         }
         else if (stopAtNonOption)
         {
             eatTheRest = true;
-            tokens.add(token);
         }
+
+        tokens.add(token);
     }
 
     /**

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/PosixParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/PosixParserTest.java?rev=680289&r1=680288&r2=680289&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/PosixParserTest.java (original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/PosixParserTest.java Mon Jul 28 01:43:28 2008
@@ -100,6 +100,21 @@
         }
     }
 
+    public void testUnrecognizedOption2() throws Exception
+    {
+        String[] args = new String[] { "-z", "-abtoast", "foo", "bar" };
+
+        try
+        {
+            parser.parse(options, args);
+            fail("UnrecognizedOptionException wasn't thrown");
+        }
+        catch (UnrecognizedOptionException e)
+        {
+            assertEquals("-z", e.getOption());
+        }
+    }
+
     public void testMissingArg() throws Exception
     {
         String[] args = new String[] { "-acb" };