File tree Expand file tree Collapse file tree
java/org/apache/commons/cli
test/org/apache/commons/cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,6 +91,9 @@ public class CommandLine {
9191 /** the processed options */
9292 private Map options = new HashMap ();
9393
94+ /** the option name map */
95+ private Map names = new HashMap ();
96+
9497 /** Map of unique options for ease to get complete list of options */
9598 private Map hashcodeMap = new HashMap ();
9699
@@ -179,8 +182,13 @@ public String getOptionValue( char opt ) {
179182 public String [] getOptionValues ( String opt ) {
180183 List values = new java .util .ArrayList ();
181184
182- if ( options .containsKey ( opt ) ) {
183- List opts = (List )options .get ( opt );
185+ String key = opt ;
186+ if ( names .containsKey ( opt ) ) {
187+ key = (String )names .get ( opt );
188+ }
189+
190+ if ( options .containsKey ( key ) ) {
191+ List opts = (List )options .get ( key );
184192 Iterator iter = opts .iterator ();
185193
186194 while ( iter .hasNext () ) {
@@ -290,6 +298,9 @@ void addOption( Option opt ) {
290298 if ( " " .equals (key ) ) {
291299 key = opt .getLongOpt ();
292300 }
301+ else {
302+ names .put ( opt .getLongOpt (), key );
303+ }
293304
294305 if ( options .get ( key ) != null ) {
295306 ((java .util .List )options .get ( key )).add ( opt );
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ public void testSimpleLong()
8787 assertTrue ( "Confirm -a is set" , cl .hasOption ("a" ) );
8888 assertTrue ( "Confirm -b is set" , cl .hasOption ("b" ) );
8989 assertTrue ( "Confirm arg of -b" , cl .getOptionValue ("b" ).equals ("toast" ) );
90+ assertTrue ( "Confirm arg of --bfile" , cl .getOptionValue ( "bfile" ).equals ( "toast" ) );
9091 assertTrue ( "Confirm size of extra args" , cl .getArgList ().size () == 2 );
9192 }
9293 catch (ParseException e )
You can’t perform that action at this time.
0 commit comments