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 2009/05/28 13:06:57 UTC

svn commit: r779562 - /commons/proper/cli/trunk/src/java/org/apache/commons/cli/AmbiguousOptionException.java

Author: ebourg
Date: Thu May 28 11:06:57 2009
New Revision: 779562

URL: http://svn.apache.org/viewvc?rev=779562&view=rev
Log:
Improved the message of AmbiguousOptionException

Modified:
    commons/proper/cli/trunk/src/java/org/apache/commons/cli/AmbiguousOptionException.java

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli/AmbiguousOptionException.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli/AmbiguousOptionException.java?rev=779562&r1=779561&r2=779562&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli/AmbiguousOptionException.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli/AmbiguousOptionException.java Thu May 28 11:06:57 2009
@@ -18,6 +18,7 @@
 package org.apache.commons.cli;
 
 import java.util.Collection;
+import java.util.Iterator;
 
 /**
  * Exception thrown when an option can't be identified from a partial name.
@@ -39,7 +40,7 @@
      */
     public AmbiguousOptionException(String option, Collection matchingOptions)
     {
-        super("Ambiguous option: " + option, option);
+        super(createMessage(option, matchingOptions), option);
         this.matchingOptions = matchingOptions;
     }
 
@@ -50,4 +51,33 @@
     {
         return matchingOptions;
     }
+
+    /**
+     * Build the exception message from the specified list of options.
+     * 
+     * @param option
+     * @param matchingOptions
+     * @return
+     */
+    private static String createMessage(String option, Collection matchingOptions)
+    {
+        StringBuffer buff = new StringBuffer("Ambiguous option: '");
+        buff.append(option);
+        buff.append("'  (could be: ");
+
+        Iterator it = matchingOptions.iterator();
+        while (it.hasNext())
+        {
+            buff.append("'");
+            buff.append(it.next());
+            buff.append("'");
+            if (it.hasNext())
+            {
+                buff.append(", ");
+            }
+        }
+        buff.append(")");
+
+        return buff.toString();
+    }
 }