commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Ferguson" <Andrew.Fergu...@arm.com>
Subject RE: [CLI] commons-cli processing options incorrectly?
Date Mon, 26 Jul 2004 16:38:45 GMT
thanks very much :)

(its unlikely that I'll have time to have a look at the sources of CLI1,
but if I do I'll post something here) 

-----Original Message-----
From: Rob Oxspring [mailto:roxspring@imapmail.org] 
Sent: 21 July 2004 23:39
To: Andrew Ferguson; Jakarta Commons Developers List
Subject: Re: [CLI] commons-cli processing options incorrectly?

I've created a bugzilla entry and converted your example into a unit
test patch there:
http://issues.apache.org/bugzilla/show_bug.cgi?id=30246

It definitely looks like a bug to me, but the obvious quick fix ended up
causing test failures elsewhere.  I may come back to this and
investigate but it's more likely that I'll get CLI2 moving again and
ensure your example works against that.

Though I'm happy to apply fixing patches if people develop them.

Rob


Andrew Ferguson wrote:
> -----Original Message-----
> From: Andrew Ferguson [mailto:Andrew.Ferguson@arm.com]
> Sent: 15 July 2004 18:40
> To: Jakarta Commons Users List
> Subject: commons-cli processing options incorrectly?
> 
> hi,
> 
>  this could be me misunderstanding the posix standard but this link
> 
> 	
> http://java.sun.com/docs/books/tutorial/essential/attributes/_posix.ht
> ml
> 
>  says
> 
> 	"Options that do not require arguments can be grouped after a
hyphen, 
> so, for example, -lst is equivalent to -t -l -s."
> 
> 
>  but the following code:
> 
> 	import org.apache.commons.cli.*;
> 	import java.util.*;
> 	
> 	public class CLITest {
> 		public static void main(String[]arg) throws Exception {
> 			CommandLineParser parser = new PosixParser();
> 	
> 			Options options = new Options();
> 			
> 			Option p = new Option("p", "pets", true, "takes
a list of up to 4 
> animals");
> 			p.setArgs(4);
> 			p.setRequired(true);
> 			
> 			Option v = new Option("v", "vet", true, "the
name of a vet");
> 			v.setArgs(100);
> 			v.setRequired(true);
> 			
> 			options.addOption(p).addOption(v);
> 	
> 			CommandLine line = parser.parse(options, arg);
> 			
> 			System.out.println("p ? "+line.hasOption("p")+"
> "+Arrays.asList(line.getOptionValues("p")));
> 			System.out.println("v ? "+line.hasOption("v")+"
> "+Arrays.asList(line.getOptionValues("v")));
> 		}
> 	}
> 
>  produces these results
> 
> 	y:\java\misc>java CLITest -p 1 2 3 -v 4 5 6
> 	p ? true [1, 2, 3]
> 	v ? true [4, 5, 6]
> 
> 	y:\java\misc>java CLITest -p 1 2 v 3 -v 4 5 6
> 	p ? true [1, 2]
> 	v ? true [4, 5, 6]
> 	
> 	y:\java\misc>java CLITest -p 1 v 2 3 -v 4 5 6
> 	p ? true [1]
> 	v ? true [4, 5, 6]
> 
> 	y:\java\misc>java CLITest -p 1 V 2 3 -v 4 5 6
> 	p ? true [1, V, 2, 3]
> 	v ? true [4, 5, 6]
> 
>  when I was expecting: (* marks different from above)
> 
> 	y:\java\misc>java CLITest -p 1 2 3 -v 4 5 6
> 	p ? true [1, 2, 3]
> 	v ? true [4, 5, 6]
> 
> 	y:\java\misc>java CLITest -p 1 2 v 3 -v 4 5 6
> *	p ? true [1, 2, v, 3] 
> 	v ? true [4, 5, 6]
> 
> 	y:\java\misc>java CLITest -p 1 v 2 3 -v 4 5 6
> *	p ? true [1, v, 2, 3]
> 	v ? true [4, 5, 6]
> 
> 	y:\java\misc>java CLITest -p 1 V 2 3 -v 4 5 6
> 	p ? true [1, V, 2, 3]
> 	v ? true [4, 5, 6]
> 
> I'm constantly misunderstanding how command lines are meant to be 
> interpreted, but this seems wrong??
> 
> thanks,
> Andrew
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> 




---------------------------------------------------------------------
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