commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject [01/50] [abbrv] commons-cli git commit: CLI-252: LongOpt falsely detected as ambiguous. This closes #2 from github. Thanks to Simon Harrer.
Date Thu, 08 Jun 2017 17:36:30 GMT
Repository: commons-cli
Updated Branches:
  refs/heads/master [created] 92f1def0b


CLI-252: LongOpt falsely detected as ambiguous. This closes #2 from github. Thanks to Simon
Harrer.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@1684315 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/commons-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-cli/commit/085a1538
Tree: http://git-wip-us.apache.org/repos/asf/commons-cli/tree/085a1538
Diff: http://git-wip-us.apache.org/repos/asf/commons-cli/diff/085a1538

Branch: refs/heads/master
Commit: 085a1538fa20d8e48faad49eaffd697f024bf1af
Parents: a154084
Author: Benedikt Ritter <britter@apache.org>
Authored: Tue Jun 9 05:18:22 2015 +0000
Committer: Benedikt Ritter <britter@apache.org>
Committed: Tue Jun 9 05:18:22 2015 +0000

----------------------------------------------------------------------
 src/changes/changes.xml                         |  3 +++
 .../java/org/apache/commons/cli/Options.java    |  7 +++++-
 .../apache/commons/cli/bug/BugCLI252Test.java   | 25 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-cli/blob/085a1538/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3bcbcb6..3dc6362 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -23,6 +23,9 @@
   <body>
 
     <release version="1.4" date="tba" description="tba">
+      <action type="fix" dev="britter" issue="CLI-252" due-to="Simon Harrer">
+        LongOpt falsely detected as ambiguous
+      </action>
     </release>
 
     <release version="1.3" date="2015-05-09" description="This is a feature and maintenance
bug fix release.">

http://git-wip-us.apache.org/repos/asf/commons-cli/blob/085a1538/src/main/java/org/apache/commons/cli/Options.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/cli/Options.java b/src/main/java/org/apache/commons/cli/Options.java
index 5b73db6..798b176 100644
--- a/src/main/java/org/apache/commons/cli/Options.java
+++ b/src/main/java/org/apache/commons/cli/Options.java
@@ -235,7 +235,12 @@ public class Options implements Serializable
         opt = Util.stripLeadingHyphens(opt);
         
         List<String> matchingOpts = new ArrayList<String>();
-        
+
+        // for a perfect match return the single option only
+        if(longOpts.keySet().contains(opt)) {
+            return Collections.singletonList(opt);
+        }
+
         for (String longOpt : longOpts.keySet())
         {
             if (longOpt.startsWith(opt))

http://git-wip-us.apache.org/repos/asf/commons-cli/blob/085a1538/src/test/java/org/apache/commons/cli/bug/BugCLI252Test.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/cli/bug/BugCLI252Test.java b/src/test/java/org/apache/commons/cli/bug/BugCLI252Test.java
new file mode 100644
index 0000000..53b80ce
--- /dev/null
+++ b/src/test/java/org/apache/commons/cli/bug/BugCLI252Test.java
@@ -0,0 +1,25 @@
+package org.apache.commons.cli.bug;
+
+import org.apache.commons.cli.*;
+import org.junit.Test;
+
+public class BugCLI252Test extends DefaultParserTest {
+
+    @Test
+    public void testExactOptionNameMatch() throws ParseException {
+        new DefaultParser().parse(getOptions(), new String[]{"--prefix"});
+    }
+
+    @Test(expected = AmbiguousOptionException.class)
+    public void testAmbiquousOptionName() throws ParseException {
+        new DefaultParser().parse(getOptions(), new String[]{"--pref"});
+    }
+
+    private Options getOptions() {
+        Options options = new Options();
+        options.addOption(Option.builder().longOpt("prefix").build());
+        options.addOption(Option.builder().longOpt("prefixplusplus").build());
+        return options;
+    }
+
+}


Mime
View raw message