groovy

CLIBuilder regression since 1.5.1

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.5.4
  • Fix Version/s: 1.5.5, 1.6-beta-1
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows XP, Java 1.5.0_12-b04
  • Number of attachments :
    0

Description

A coworker has found a regression since 1.5.1 with the CLIBuilder.

He is trying to get the CLIParser to read a "-s loc" parameter. It works with Groovy 1.5.1, but it does not work with 1.5.4 or the current 1.6 snapshot jar.

Here is how to reproduce the problem.

First put commons-cli-1.1.jar in {user.home}/.groovy/lib. Then remove the commons-cli-1.0.jar in the groovy installation.

Then:

C:\>set GROOVY_HOME=c:\java\groovy-1.5.1

C:\>set PATH=%GROOVY_HOME%\bin;%PATH%

C:\>groovy -version
Groovy Version: 1.5.1 JVM: 1.5.0_12-b04
C:\>
C:\>
C:\>groovy -e "def cli = new CliBuilder( usage: 'groovy' ); cli.s(longOpt: 'loc', required: true, args: 1, ''); cli.parse(['-s', 'blah'] as String[])"
C:\>
C:\>
C:\>
C:\>
C:\>set GROOVY_HOME=c:\java\groovy-1.5.4

C:\>set PATH=%GROOVY_HOME%\bin;%PATH%

C:\>groovy -version
Groovy Version: 1.5.4 JVM: 1.5.0_12-b04

C:\>groovy -e "def cli = new CliBuilder( usage: 'groovy' ); cli.s(longOpt: 'loc', required: true, args: 1, ''); cli.parse(['-s', 'blah'] as String[])"
error: Missing required option: s
usage: groovy
 -s,--loc <arg>

C:\>

This also does not work with commons-cli-1.0.jar and Groovy 1.5.4 (but it does work with Groovy 1.5.1 and cli-1.0):

C:\>groovy -e "def cli = new CliBuilder( usage: 'groovy' ); cli.s(longOpt: 'loc', required: true, args: 1, ''); cli.parse(['-s', 'blah'] as String[])"
error: -s
usage: groovy
 -s,--loc

C:\>

Activity

Hide
Paul King added a comment -

add code tags

Show
Paul King added a comment - add code tags
Hide
Paul King added a comment - - edited

I am unable to reproduce this problem. Can you try these two variations:

java -cp %PATH_TO_GROOVY%\embeddable\groovy-all-1.5.4.jar;%PATH_TO_CLI%\commons-cli-1.0.jar groovy.lang.GroovyShell test.groovy
java -cp %PATH_TO_GROOVY%\embeddable\groovy-all-1.5.4.jar;%PATH_TO_CLI%\commons-cli-1.1.jar groovy.lang.GroovyShell test.groovy

where test.groovy contains something like:

test.groovy
def cli = new CliBuilder( usage: 'groovy' )
cli.s(longOpt: 'loc', required: true, args: 1, '')
cli.parse(['-s', 'blah'] as String[])
Show
Paul King added a comment - - edited I am unable to reproduce this problem. Can you try these two variations:
java -cp %PATH_TO_GROOVY%\embeddable\groovy-all-1.5.4.jar;%PATH_TO_CLI%\commons-cli-1.0.jar groovy.lang.GroovyShell test.groovy
java -cp %PATH_TO_GROOVY%\embeddable\groovy-all-1.5.4.jar;%PATH_TO_CLI%\commons-cli-1.1.jar groovy.lang.GroovyShell test.groovy
where test.groovy contains something like:
test.groovy
def cli = new CliBuilder( usage: 'groovy' )
cli.s(longOpt: 'loc', required: true, args: 1, '')
cli.parse(['-s', 'blah'] as String[])
Hide
Kevin DeBruhl added a comment -

I tried the two variations and they work as documented and expected.

However, I think the problem lies in the parsing of the options from the variable 'args'. If the test.groovy program is changed as follows:

test2.groovy
def cli = new CliBuilder( usage: 'groovy' )
cli.s(longOpt: 'loc', required: true, args: 1, '')
cli.parse(args)

Then, using java directly still works, but using groovy.bat does not.

Show
Kevin DeBruhl added a comment - I tried the two variations and they work as documented and expected. However, I think the problem lies in the parsing of the options from the variable 'args'. If the test.groovy program is changed as follows:
test2.groovy
def cli = new CliBuilder( usage: 'groovy' )
cli.s(longOpt: 'loc', required: true, args: 1, '')
cli.parse(args)
Then, using java directly still works, but using groovy.bat does not.
Hide
Paul King added a comment -

I believe this was fixed as part of GROOVY-2690

Show
Paul King added a comment - I believe this was fixed as part of GROOVY-2690

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: