4 messages in org.codehaus.groovy.userRe: [groovy-user] How much of CliBuil...
FromSent OnAttachments
Bogdan CalmacMar 17, 2008 5:55 pm 
Gerrit GeensMar 18, 2008 12:05 am 
Russel WinderMar 18, 2008 12:33 am 
Russel WinderMar 18, 2008 12:40 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [groovy-user] How much of CliBuilder does work?Actions...
From:Gerrit Geens (gerr@gmail.com)
Date:Mar 18, 2008 12:05:02 am
List:org.codehaus.groovy.user

There are a number of issues with the Commons CLI 1.0/1.1 classes (that have nothing to do with Groovy itself!). A bunch of them are listed in the CliBuilderTest.groovy sources.

One of these issues is that your first example won't work with the default Posix parser: * <p>There appear to be issues when using the <code>PosixParser</code> &ndash; when an option with a * parameter is passed using a long form and a single letter parameter of some sort has been declared (the * problem does not occur if no single letter option has been declared) then the value "--" is returned * instead of the option parameter value. This problem does not happen using the * <code>GnuParser</code>.</p>

If you change the example to use the Gnu parser then it will work:

def cli = new CliBuilder(usage: 'groovy Hello -t', parser: new org.apache.commons.cli.GnuParser ()) cli.t(argName:'person', longOpt:'to', args:1, required:true, 'person to say hello to') opt = cli.parse(['--to', 'me']) println "t: $opt.t"

Will print:

t: me

With regards to your second problem: in the current version you should use the short name to get the value.

Personally I've had so much issues with CLI 1.0/1.1 that I started developing a new Groovy builder for Commons CLI 2. Even though the CLI 2 library is not really released and development has stalled IMHO CLI 2 gives me less headaches ;-)

Gerrit

On Tue, Mar 18, 2008 at 1:55 AM, Bogdan Calmac <bcal@gmail.com> wrote:

I try to create a sample HelloWorld script according to the Mailman example from "Groovy in Action" and some basic things don't seem to work. I apologize in advance if it's only my ignorance.

1. an option is not recognized when using the long arg form

Here I create a CLI with a single required argument and try to use the long arg form:

def cli = new CliBuilder(usage: 'groovy Hello -t') cli.t(argName:'person', longOpt:'to', args:1, required:true, 'person to say hello to') opt = cli.parse(['--to', 'me']) println "t: $opt.t"

It prints out:

t: --

instead of

t: me

2. the option cannot be accessed with argName as described in the book: "If an argName such as myArgName was specified for the x option, then options.x and options.myArgName return the same value"

Here I use the same CLI and try to access the value with opt.person:

def cli = new CliBuilder(usage: 'groovy Hello -t') cli.t(argName:'person', longOpt:'to', args:1, required:true, 'person to say hello to') opt = cli.parse(['-t', 'me']) println "person: $opt.person"

It prints out:

person: false

which means it doesn't know about the 'person' argName.

The same thing happens if the arguments are passed in the cmdline. I've put everything in the script to make it easier for you to run. I am using groovy 1.5.4.

In case these are known limitations of the upstream library, is there any other obvious problem I should guard against? -- View this message in context: http://www.nabble.com/How-much-of-CliBuilder-does-work--tp16111825p16111825.html Sent from the groovy - user mailing list archive at Nabble.com.

--------------------------------------------------------------------- To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email