commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r589237 - in /commons/proper/cli/trunk/src: java/org/apache/commons/cli2/option/ArgumentImpl.java java/org/apache/commons/cli2/option/ParentImpl.java test/org/apache/commons/cli2/bug/BugCLI122Test.java
Date Sat, 27 Oct 2007 23:05:40 GMT
Author: bayard
Date: Sat Oct 27 16:05:31 2007
New Revision: 589237

URL: http://svn.apache.org/viewvc?rev=589237&view=rev
Log:
Applying Brian Egge's fix and test from CLI-122

Added:
    commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java   (with
props)
Modified:
    commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java
    commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java?rev=589237&r1=589236&r2=589237&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java Sat
Oct 27 16:05:31 2007
@@ -143,17 +143,18 @@
         int argumentCount = commandLine.getValues(option, Collections.EMPTY_LIST).size();
 
         while (arguments.hasNext() && (argumentCount < maximum)) {
-            final String allValues = stripBoundaryQuotes((String) arguments.next());
+            final String allValuesQuoted = (String) arguments.next();
+            final String allValues = stripBoundaryQuotes(allValuesQuoted);
 
             // should we ignore things that look like options?
-            if (allValues.equals(consumeRemaining)) {
+            if (allValuesQuoted.equals(consumeRemaining)) {
                 while (arguments.hasNext() && (argumentCount < maximum)) {
                     ++argumentCount;
                     commandLine.addValue(option, arguments.next());
                 }
             }
             // does it look like an option?
-            else if (commandLine.looksLikeOption(allValues)) {
+            else if (commandLine.looksLikeOption(allValuesQuoted)) {
                 arguments.previous();
 
                 break;

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java?rev=589237&r1=589236&r2=589237&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ParentImpl.java Sat Oct
27 16:05:31 2007
@@ -217,7 +217,13 @@
         if (initialIndex > 0) {
             arguments.remove();
             arguments.add(newArgument.substring(0, initialIndex));
-            arguments.add(newArgument.substring(initialIndex + 1));
+            String value = newArgument.substring(initialIndex + 1);
+            // The value obviously isn't an option, so we need to quote it if looks like
an option.
+            // The quotes will be removed later
+            if (value.startsWith("-")) {
+                value = '"' + value + '"';
+            }
+            arguments.add(value);
             arguments.previous();
         }
 

Added: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java?rev=589237&view=auto
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java (added)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java Sat Oct
27 16:05:31 2007
@@ -0,0 +1,45 @@
+package org.apache.commons.cli2.bug;
+
+import junit.framework.TestCase;
+import org.apache.commons.cli2.*;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+import org.apache.commons.cli2.validation.FileValidator;
+
+/**
+ * @author brianegge
+ */
+public class BugCLI122Test extends TestCase {
+    public void testArgumentWhichStartsWithDash() throws OptionException {
+        Argument wdArg = new ArgumentBuilder()
+                .withName("anything")
+                .withMaximum(1)
+                .withMinimum(1)
+                .withInitialSeparator('=')
+                .create();
+
+        Option wdOpt = new DefaultOptionBuilder().withArgument(wdArg)
+                .withDescription("anything, foo or -foo")
+                .withLongName("argument")
+                .withShortName("a")
+                .create();
+
+        Group group = new GroupBuilder().withOption(wdOpt).create();
+
+        Parser p = new Parser();
+        p.setGroup(group);
+        CommandLine normal = p.parse (new String[]{"-a", "foo"});
+        assertNotNull(normal);
+        assertEquals(normal.getValue(wdOpt), "foo");
+
+        CommandLine withDash = p.parse (new String[]{"--argument", "\"-foo\""});
+        assertNotNull(withDash);
+        assertEquals("-foo", withDash.getValue(wdOpt));
+
+        CommandLine withDashAndEquals = p.parse (new String[]{"--argument=-foo"});
+        assertNotNull(withDashAndEquals);
+        assertEquals("-foo", withDashAndEquals.getValue(wdOpt));
+    }
+}

Propchange: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message