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:[EMAIL PROTECTED] 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.html

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to