File tree Expand file tree Collapse file tree
main/java/org/apache/commons/cli
test/java/org/apache/commons/cli/bug Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323 <body >
2424
2525 <release version =" 1.4" date =" tba" description =" tba" >
26+ <action type =" fix" dev =" britter" issue =" CLI-252" due-to =" Simon Harrer" >
27+ LongOpt falsely detected as ambiguous
28+ </action >
2629 </release >
2730
2831 <release version =" 1.3" date =" 2015-05-09" description =" This is a feature and maintenance bug fix release." >
Original file line number Diff line number Diff line change @@ -235,7 +235,12 @@ public List<String> getMatchingOptions(String opt)
235235 opt = Util .stripLeadingHyphens (opt );
236236
237237 List <String > matchingOpts = new ArrayList <String >();
238-
238+
239+ // for a perfect match return the single option only
240+ if (longOpts .keySet ().contains (opt )) {
241+ return Collections .singletonList (opt );
242+ }
243+
239244 for (String longOpt : longOpts .keySet ())
240245 {
241246 if (longOpt .startsWith (opt ))
Original file line number Diff line number Diff line change 1+ package org .apache .commons .cli .bug ;
2+
3+ import org .apache .commons .cli .*;
4+ import org .junit .Test ;
5+
6+ public class BugCLI252Test extends DefaultParserTest {
7+
8+ @ Test
9+ public void testExactOptionNameMatch () throws ParseException {
10+ new DefaultParser ().parse (getOptions (), new String []{"--prefix" });
11+ }
12+
13+ @ Test (expected = AmbiguousOptionException .class )
14+ public void testAmbiquousOptionName () throws ParseException {
15+ new DefaultParser ().parse (getOptions (), new String []{"--pref" });
16+ }
17+
18+ private Options getOptions () {
19+ Options options = new Options ();
20+ options .addOption (Option .builder ().longOpt ("prefix" ).build ());
21+ options .addOption (Option .builder ().longOpt ("prefixplusplus" ).build ());
22+ return options ;
23+ }
24+
25+ }
You can’t perform that action at this time.
0 commit comments