File tree Expand file tree Collapse file tree
src/java/org/apache/commons/cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818package org .apache .commons .cli ;
1919
2020import java .util .Collection ;
21+ import java .util .Iterator ;
2122
2223/**
2324 * Exception thrown when an option can't be identified from a partial name.
@@ -39,7 +40,7 @@ public class AmbiguousOptionException extends UnrecognizedOptionException
3940 */
4041 public AmbiguousOptionException (String option , Collection matchingOptions )
4142 {
42- super ("Ambiguous option: " + option , option );
43+ super (createMessage ( option , matchingOptions ) , option );
4344 this .matchingOptions = matchingOptions ;
4445 }
4546
@@ -50,4 +51,33 @@ public Collection getMatchingOptions()
5051 {
5152 return matchingOptions ;
5253 }
54+
55+ /**
56+ * Build the exception message from the specified list of options.
57+ *
58+ * @param option
59+ * @param matchingOptions
60+ * @return
61+ */
62+ private static String createMessage (String option , Collection matchingOptions )
63+ {
64+ StringBuffer buff = new StringBuffer ("Ambiguous option: '" );
65+ buff .append (option );
66+ buff .append ("' (could be: " );
67+
68+ Iterator it = matchingOptions .iterator ();
69+ while (it .hasNext ())
70+ {
71+ buff .append ("'" );
72+ buff .append (it .next ());
73+ buff .append ("'" );
74+ if (it .hasNext ())
75+ {
76+ buff .append (", " );
77+ }
78+ }
79+ buff .append (")" );
80+
81+ return buff .toString ();
82+ }
5383}
You can’t perform that action at this time.
0 commit comments