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 11:47:06 UTC
svn commit: r680299 - 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 02:47:05 2008
New Revision: 680299
URL: http://svn.apache.org/viewvc?rev=680299&view=rev
Log:
Fixed PosixParser when an unrecognized long option is found (CLI-165)
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=680299&r1=680298&r2=680299&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 02:47:05 2008
@@ -108,17 +108,22 @@
// get the next command line token
String token = (String) iter.next();
- // handle SPECIAL TOKEN
+ // handle long option --foo or --foo=bar
if (token.startsWith("--"))
{
- if (token.indexOf('=') != -1)
+ int pos = token.indexOf('=');
+ String opt = pos == -1 ? token : token.substring(0, pos); // --foo
+
+ if (!options.hasOption(opt) && stopAtNonOption)
{
- tokens.add(token.substring(0, token.indexOf('=')));
- tokens.add(token.substring(token.indexOf('=') + 1, token.length()));
+ process(token);
}
else
{
- tokens.add(token);
+ tokens.add(opt);
+ if (pos != -1) {
+ tokens.add(token.substring(pos + 1));
+ }
}
}
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=680299&r1=680298&r2=680299&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 02:47:05 2008
@@ -156,6 +156,19 @@
assertTrue("Confirm 3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
}
+ public void testStop3() throws Exception
+ {
+ String[] args = new String[]{"--zop==1",
+ "-abtoast",
+ "--b=bar"};
+
+ CommandLine cl = parser.parse(options, args, true);
+
+ assertFalse("Confirm -a is not set", cl.hasOption("a"));
+ assertFalse("Confirm -b is not set", cl.hasOption("b"));
+ assertTrue("Confirm 3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
+ }
+
public void testStopBursting() throws Exception
{
String[] args = new String[] { "-azc" };