commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jke...@apache.org
Subject cvs commit: jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2 CommandLine.java
Date Wed, 29 Oct 2003 08:34:56 GMT
jkeyes      2003/10/29 00:34:56

  Modified:    cli/src/test/org/apache/commons/cli2 ArgumentTest.java
               cli/src/java/org/apache/commons/cli2 CommandLine.java
  Log:
  
- defaults can now be supplied at interrogation time (Bug
   24046)
- values specified
at interrogation time override those
   specified at definition time
  
  Revision  Changes    Path
  1.5       +32 -6     jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/ArgumentTest.java
  
  Index: ArgumentTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/ArgumentTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ArgumentTest.java	29 Oct 2003 01:28:16 -0000	1.4
  +++ ArgumentTest.java	29 Oct 2003 08:34:56 -0000	1.5
  @@ -532,7 +532,7 @@
           assertFalse(iterator.hasNext());
       }
       
  -    public void testProcess_DefaultValue() throws OptionException {
  +    public void testProcess_DefinedDefaultValue() throws OptionException {
           final Option size = buildSizeArgument();
           final List args = list("-size");
           final CommandLine commandLine = commandLine(size, args);
  @@ -540,10 +540,10 @@
           
           size.process(commandLine, iterator);
           
  -        assertEquals(commandLine.getValue(size), "10");
  +        assertEquals("10", commandLine.getValue(size));
       }
   
  -    public void testProcess_DefaultValues() throws OptionException {
  +    public void testProcess_DefinedDefaultValues() throws OptionException {
           final Option bounds = buildBoundsArgument();
           final List args = list("-bounds");
           final CommandLine commandLine = commandLine(bounds, args);
  @@ -556,4 +556,30 @@
           values.add("10");
           assertEquals(values, commandLine.getValues(bounds));
       }
  +
  +    public void testProcess_InterrogatedDefaultValue() throws OptionException {
  +        final Option size = buildSizeArgument();
  +        final List args = list("-size");
  +        final CommandLine commandLine = commandLine(size, args);
  +        final ListIterator iterator = args.listIterator();
  +        
  +        size.process(commandLine, iterator);
  +        
  +        assertEquals(new Integer(20), commandLine.getValue(size, new Integer(20)));
  +    }
  +    
  +    public void testProcess_InterrogatedDefaultValues() throws OptionException {
  +        final Option bounds = buildBoundsArgument();
  +        final List args = list("-bounds");
  +        final CommandLine commandLine = commandLine(bounds, args);
  +        final ListIterator iterator = args.listIterator();
  +        
  +        bounds.process(commandLine, iterator);
  +        
  +        List values = new ArrayList();
  +        values.add("50");
  +        values.add("100");
  +        assertEquals(values, commandLine.getValues(bounds, values));
  +    }
  +
   }
  
  
  
  1.7       +40 -11    jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/CommandLine.java
  
  Index: CommandLine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/CommandLine.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CommandLine.java	29 Oct 2003 01:28:17 -0000	1.6
  +++ CommandLine.java	29 Oct 2003 08:34:56 -0000	1.7
  @@ -137,10 +137,21 @@
   		return getValues(getOption(trigger));
   	}
   
  -	public List getValues(final Option option) {
  +    public List getValues(final String trigger, final List defaultValues) {
  +        return getValues(getOption(trigger), defaultValues);
  +    }
  +
  +    public List getValues(final Option option) {
  +        return getValues(option, null);
  +    }
  +    
  +	public List getValues(final Option option, final List defaultValues) {
   		final List valueList = (List) values.get(option);
   		if (valueList == null) {
  -            if (this.defaults != null &&
  +            if (defaultValues != null) {
  +                return defaultValues;
  +            }
  +            else if (this.defaults != null &&
                   this.defaults.containsKey(option)) {
                       
                   return (List) this.defaults.get(option);
  @@ -154,15 +165,33 @@
   		}
   	}
   
  -	public Object getValue(final String trigger) {
  -		return getValue(getOption(trigger));
  -	}
  +    public Object getValue(final String trigger) {
  +        return getValue(getOption(trigger));
  +    }
   
  -	public Object getValue(final Option option) {
  -		List values = getValues(option);
  +    public Object getValue(final String trigger, final Object defaultValue) {
  +        return getValue(getOption(trigger), defaultValue);
  +    }
  +
  +    public Object getValue(final Option option) {
  +        return getValue(option, null);
  +    }
  +    
  +	public Object getValue(final Option option, final Object defaultValue) {
  +	
  +    	List values = null;
  +
  +        if (defaultValue == null) {
  +            values = getValues(option);
  +        }
  +        else {
  +            final List tmpDefaults = new ArrayList(1);
  +            tmpDefaults.add(defaultValue);
  +            values = getValues(option, tmpDefaults);             
  +        }
           
   		if (values == null || values.isEmpty()) {
  -            
  +    
               if (this.defaults != null &&
                   this.defaults.containsKey(option)) {
                       
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message