Kallin Nagelberg | 15 Jul 22:56

[groovy-user] CliBuilder inserts arguments

I am using a CliBuilder like:

CliBuilder cli = new CliBuilder(usage: usage)
cli.A(longOpt: 'mainargs', required: false, args: UNLIMITED_VALUES, 'arguments for the main method')

UNLIMITED VALUES is a constant from the Option class.

i notice when i run this from the command line like:
groovy myscript.groovy -A asdf asdf asdf asdf

There is an extra entry in the list, always at the second position:
when I do a 'println opts.As' I get:
["asdf", "--", "asdf", "asdf", "asdf"]

Is this a known issue?



Russel Winder | 16 Jul 16:53

Re: [groovy-user] CliBuilder inserts arguments

On Tue, 2008-07-15 at 17:00 -0400, Kallin Nagelberg wrote:
> I am using a CliBuilder like:
> 
> CliBuilder cli = new CliBuilder(usage: usage)
> cli.A(longOpt: 'mainargs', required: false, args: UNLIMITED_VALUES,
> 'arguments for the main method')
> 
> UNLIMITED VALUES is a constant from the Option class.

UNLIMITED_VALUES may not do what you think it does.  Moreover the
semantics changed between Commons CLI 1.0 and 1.1, and may well change
again in 1.2 (back to 1.0 :-).

Moreover the behaviour of the default PosixParser is broken, you
probably want to use the GnuParser which is significantly less broken.

> i notice when i run this from the command line like:
> groovy myscript.groovy -A asdf asdf asdf asdf
> 
> There is an extra entry in the list, always at the second position:
> when I do a 'println opts.As' I get:
> ["asdf", "--", "asdf", "asdf", "asdf"]
> 
> Is this a known issue?

Oh yes :-(

CliBuilder uses the PosixParser by default, and as far as I can tell it
is completely broken when it comes to doing anything associated with
actually parsing options.  GnuParser may help out here:

	def cli = new CliBuilder ( usage : usage , parser : new GnuParser ( ) )

A number of people are praising JOpt Simple but as far as I can tell it
does not yet do as much as Commons CLI is supposed to do.  Why the
person chose to start again with JOpt Simple rather than fix Commons CLI
is a question I cannot answer but it would be interesting to know.

--

-- 
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077
Kallin Nagelberg | 16 Jul 19:03

Re: [groovy-user] CliBuilder inserts arguments

Ok thanks, I'll try that.
I'm also noticing that the parser is stripping double quotes from my arguments. Is there a way to prevent that? I'm trying to allow groovy lists,maps as arguments.

On Wed, Jul 16, 2008 at 10:53 AM, Russel Winder <russel.winder-DsImGR7CbQu8rjiVs5Nzzw@public.gmane.org> wrote:
On Tue, 2008-07-15 at 17:00 -0400, Kallin Nagelberg wrote:
> I am using a CliBuilder like:
>
> CliBuilder cli = new CliBuilder(usage: usage)
> cli.A(longOpt: 'mainargs', required: false, args: UNLIMITED_VALUES,
> 'arguments for the main method')
>
> UNLIMITED VALUES is a constant from the Option class.

UNLIMITED_VALUES may not do what you think it does.  Moreover the
semantics changed between Commons CLI 1.0 and 1.1, and may well change
again in 1.2 (back to 1.0 :-).

Moreover the behaviour of the default PosixParser is broken, you
probably want to use the GnuParser which is significantly less broken.

> i notice when i run this from the command line like:
> groovy myscript.groovy -A asdf asdf asdf asdf
>
> There is an extra entry in the list, always at the second position:
> when I do a 'println opts.As' I get:
> ["asdf", "--", "asdf", "asdf", "asdf"]
>
> Is this a known issue?

Oh yes :-(

CliBuilder uses the PosixParser by default, and as far as I can tell it
is completely broken when it comes to doing anything associated with
actually parsing options.  GnuParser may help out here:

       def cli = new CliBuilder ( usage : usage , parser : new GnuParser ( ) )

A number of people are praising JOpt Simple but as far as I can tell it
does not yet do as much as Commons CLI is supposed to do.  Why the
person chose to start again with JOpt Simple rather than fix Commons CLI
is a question I cannot answer but it would be interesting to know.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077

Kallin Nagelberg | 16 Jul 19:06

Re: [groovy-user] CliBuilder inserts arguments

Actually nvm that is my shell that's doing that.

On Wed, Jul 16, 2008 at 1:03 PM, Kallin Nagelberg <kallin.nagelberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Ok thanks, I'll try that.
I'm also noticing that the parser is stripping double quotes from my arguments. Is there a way to prevent that? I'm trying to allow groovy lists,maps as arguments.


On Wed, Jul 16, 2008 at 10:53 AM, Russel Winder <russel.winder-DsImGR7CbQu8rjiVs5Nzzw@public.gmane.org> wrote:
On Tue, 2008-07-15 at 17:00 -0400, Kallin Nagelberg wrote:
> I am using a CliBuilder like:
>
> CliBuilder cli = new CliBuilder(usage: usage)
> cli.A(longOpt: 'mainargs', required: false, args: UNLIMITED_VALUES,
> 'arguments for the main method')
>
> UNLIMITED VALUES is a constant from the Option class.

UNLIMITED_VALUES may not do what you think it does.  Moreover the
semantics changed between Commons CLI 1.0 and 1.1, and may well change
again in 1.2 (back to 1.0 :-).

Moreover the behaviour of the default PosixParser is broken, you
probably want to use the GnuParser which is significantly less broken.

> i notice when i run this from the command line like:
> groovy myscript.groovy -A asdf asdf asdf asdf
>
> There is an extra entry in the list, always at the second position:
> when I do a 'println opts.As' I get:
> ["asdf", "--", "asdf", "asdf", "asdf"]
>
> Is this a known issue?

Oh yes :-(

CliBuilder uses the PosixParser by default, and as far as I can tell it
is completely broken when it comes to doing anything associated with
actually parsing options.  GnuParser may help out here:

       def cli = new CliBuilder ( usage : usage , parser : new GnuParser ( ) )

A number of people are praising JOpt Simple but as far as I can tell it
does not yet do as much as Commons CLI is supposed to do.  Why the
person chose to start again with JOpt Simple rather than fix Commons CLI
is a question I cannot answer but it would be interesting to know.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077


Russel Winder | 16 Jul 19:14

Re: [groovy-user] CliBuilder inserts arguments

On Wed, 2008-07-16 at 13:06 -0400, Kallin Nagelberg wrote:
> Actually nvm that is my shell that's doing that.
> 
> On Wed, Jul 16, 2008 at 1:03 PM, Kallin Nagelberg
> <kallin.nagelberg@...> wrote:
>         Ok thanks, I'll try that.
>         I'm also noticing that the parser is stripping double quotes
>         from my arguments. Is there a way to prevent that? I'm trying
>         to allow groovy lists,maps as arguments.

Actually it may not be, processing double dash arguments by stripping
the first dash and then processing as a single dash argument is actually
part of the PosixParser algorithm.

--

-- 
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077
Kallin Nagelberg | 16 Jul 19:30

Re: [groovy-user] CliBuilder inserts arguments

I tried

args.each {
    println it
}

and it showed all my arguments, minus the quotes :(



On Wed, Jul 16, 2008 at 1:14 PM, Russel Winder <russel.winder-DsImGR7CbQu8rjiVs5Nzzw@public.gmane.org> wrote:
On Wed, 2008-07-16 at 13:06 -0400, Kallin Nagelberg wrote:
> Actually nvm that is my shell that's doing that.
>
> On Wed, Jul 16, 2008 at 1:03 PM, Kallin Nagelberg
> <kallin.nagelberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>         Ok thanks, I'll try that.
>         I'm also noticing that the parser is stripping double quotes
>         from my arguments. Is there a way to prevent that? I'm trying
>         to allow groovy lists,maps as arguments.

Actually it may not be, processing double dash arguments by stripping
the first dash and then processing as a single dash argument is actually
part of the PosixParser algorithm.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077

Kallin Nagelberg | 16 Jul 19:32

Re: [groovy-user] CliBuilder inserts arguments

Cygwin strips them, but windows command shell doesn't...


On Wed, Jul 16, 2008 at 1:30 PM, Kallin Nagelberg <kallin.nagelberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
I tried

args.each {
    println it
}

and it showed all my arguments, minus the quotes :(




On Wed, Jul 16, 2008 at 1:14 PM, Russel Winder <russel.winder-DsImGR7CbQu8rjiVs5Nzzw@public.gmane.org> wrote:
On Wed, 2008-07-16 at 13:06 -0400, Kallin Nagelberg wrote:
> Actually nvm that is my shell that's doing that.
>
> On Wed, Jul 16, 2008 at 1:03 PM, Kallin Nagelberg
> <kallin.nagelberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>         Ok thanks, I'll try that.
>         I'm also noticing that the parser is stripping double quotes
>         from my arguments. Is there a way to prevent that? I'm trying
>         to allow groovy lists,maps as arguments.

Actually it may not be, processing double dash arguments by stripping
the first dash and then processing as a single dash argument is actually
part of the PosixParser algorithm.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077


Kallin Nagelberg | 16 Jul 19:22

Re: [groovy-user] CliBuilder inserts arguments

That being said, is there a simple way to grab command line entries and put them into groovy lists/maps?

It's tricky because all the quotes are removed, and so they cannot be directly evaluated as groovy scripts.

On Wed, Jul 16, 2008 at 1:06 PM, Kallin Nagelberg <kallin.nagelberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Actually nvm that is my shell that's doing that.


On Wed, Jul 16, 2008 at 1:03 PM, Kallin Nagelberg <kallin.nagelberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Ok thanks, I'll try that.
I'm also noticing that the parser is stripping double quotes from my arguments. Is there a way to prevent that? I'm trying to allow groovy lists,maps as arguments.


On Wed, Jul 16, 2008 at 10:53 AM, Russel Winder <russel.winder-DsImGR7CbQu8rjiVs5Nzzw@public.gmane.org> wrote:
On Tue, 2008-07-15 at 17:00 -0400, Kallin Nagelberg wrote:
> I am using a CliBuilder like:
>
> CliBuilder cli = new CliBuilder(usage: usage)
> cli.A(longOpt: 'mainargs', required: false, args: UNLIMITED_VALUES,
> 'arguments for the main method')
>
> UNLIMITED VALUES is a constant from the Option class.

UNLIMITED_VALUES may not do what you think it does.  Moreover the
semantics changed between Commons CLI 1.0 and 1.1, and may well change
again in 1.2 (back to 1.0 :-).

Moreover the behaviour of the default PosixParser is broken, you
probably want to use the GnuParser which is significantly less broken.

> i notice when i run this from the command line like:
> groovy myscript.groovy -A asdf asdf asdf asdf
>
> There is an extra entry in the list, always at the second position:
> when I do a 'println opts.As' I get:
> ["asdf", "--", "asdf", "asdf", "asdf"]
>
> Is this a known issue?

Oh yes :-(

CliBuilder uses the PosixParser by default, and as far as I can tell it
is completely broken when it comes to doing anything associated with
actually parsing options.  GnuParser may help out here:

       def cli = new CliBuilder ( usage : usage , parser : new GnuParser ( ) )

A number of people are praising JOpt Simple but as far as I can tell it
does not yet do as much as Commons CLI is supposed to do.  Why the
person chose to start again with JOpt Simple rather than fix Commons CLI
is a question I cannot answer but it would be interesting to know.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077




Gmane