You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2002/11/15 00:30:03 UTC

cvs commit: jakarta-commons/cli/src/test/org/apache/commons/cli ParseTest.java

jkeyes      2002/11/14 15:30:03

  Modified:    cli/src/java/org/apache/commons/cli CommandLine.java
               cli/src/test/org/apache/commons/cli ParseTest.java
  Log:
  added fix for Rob's problem (2), so it is now possible to query using either the opt or longOpt
  
  Revision  Changes    Path
  1.13      +13 -2     jakarta-commons/cli/src/java/org/apache/commons/cli/CommandLine.java
  
  Index: CommandLine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/CommandLine.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CommandLine.java	11 Oct 2002 23:07:34 -0000	1.12
  +++ CommandLine.java	14 Nov 2002 23:30:02 -0000	1.13
  @@ -91,6 +91,9 @@
       /** the processed options */
       private Map options = new HashMap();
   
  +    /** the option name map */
  +    private Map names   = new HashMap();
  +
       /** Map of unique options for ease to get complete list of options */
       private Map hashcodeMap = new HashMap();
   
  @@ -179,8 +182,13 @@
       public String[] getOptionValues( String opt ) {
           List values = new java.util.ArrayList();
   
  -        if( options.containsKey( opt ) ) {
  -            List opts = (List)options.get( opt );
  +        String key = opt;
  +        if( names.containsKey( opt ) ) {
  +            key = (String)names.get( opt );
  +        }
  +
  +        if( options.containsKey( key ) ) {
  +            List opts = (List)options.get( key );
               Iterator iter = opts.iterator();
   
               while( iter.hasNext() ) {
  @@ -289,6 +297,9 @@
           String key = opt.getOpt();
           if( " ".equals(key) ) {
               key = opt.getLongOpt();
  +        }
  +        else {
  +            names.put( opt.getLongOpt(), key );
           }
   
           if( options.get( key ) != null ) {
  
  
  
  1.6       +1 -0      jakarta-commons/cli/src/test/org/apache/commons/cli/ParseTest.java
  
  Index: ParseTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/ParseTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ParseTest.java	19 Sep 2002 22:59:44 -0000	1.5
  +++ ParseTest.java	14 Nov 2002 23:30:03 -0000	1.6
  @@ -87,6 +87,7 @@
               assertTrue( "Confirm -a is set", cl.hasOption("a") );
               assertTrue( "Confirm -b is set", cl.hasOption("b") );
               assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
  +            assertTrue( "Confirm arg of --bfile", cl.getOptionValue( "bfile" ).equals( "toast" ) );
               assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
           } 
           catch (ParseException e)
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>