[ 
https://issues.apache.org/jira/browse/GROOVY-8520?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16432770#comment-16432770
 ] 

Remko Popma commented on GROOVY-8520:
-------------------------------------

With picocli-3.0.0-alpha-5 and the [latest CliBuilder in my 
fork|https://github.com/remkop/groovy/blob/GROOVY_2_5_X/src/main/groovy/groovy/util/CliBuilder.groovy],
 the tests now pass with two exceptions:
* builder.CliBuilderTest::testWithArgument
* groovy.util.CliBuilderTest::testMultipleOccurrencesSeparateJuxtaposed

{code}
// TODO is this a commons-cli bug?
// In other tests, `args` restricts the total number of values for an option. 
This seems inconsistent...
void testMultipleOccurrencesSeparateJuxtaposed() {
    def cli = new CliBuilder()
//  cli.a ( longOpt : 'arg' , args : COMMONS_CLI_UNLIMITED_VALUES , 'arguments' 
) // test passes with this
    cli.a(longOpt: 'arg', args: 1, 'arguments')
    def options = cli.parse(['-a1', '-a2', '-a3'])
    assertEquals('1', options.a)
    assertEquals(['1', '2', '3'], options.as) // <-- FAILS. Actual   :[1]
    assertEquals('1', options.arg)
    assertEquals(['1', '2', '3'], options.args)
    assertEquals([], options.arguments())
}
{code}

{code}
void testWithArgument() {
    // tag::withArgument[]
    def createCli = { ->
        def cli = new CliBuilder()
        cli.a(args: 0, 'a arg') // <1>
        cli.b(args: 1, 'b arg') // <2>
        cli.c(args: 1, optionalArg: true, 'c arg') // <3>
        cli
    }
    def cli = createCli()
    def options = cli.parse('-a -b foo -c bar baz'.split()) // <4>

    assert options.a == true
    assert options.b == 'foo'
    assert options.c == 'bar'
    assert options.arguments() == ['baz']

    cli = createCli()
    options = cli.parse('-a -c -b foo bar baz'.split()) // <5>

    assert options.a == true
    assert options.c == true  // <-- FAILS. Actual: '' (empty string). 
    assert options.b == 'foo'
    assert options.arguments() == ['bar', 'baz']
    // end::withArgument[]
}
{code}

I modified the tests to create a new CliBuilder instance before parsing new 
input. It may be possible to clear all previously cached and matched values 
internally before parsing, I haven't investigated in depth yet.

Also still todo: documentation.

What are your thoughts on the failing tests above? 

> Replace commons-cli with picocli in CliBuilder
> ----------------------------------------------
>
>                 Key: GROOVY-8520
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8520
>             Project: Groovy
>          Issue Type: Improvement
>          Components: command line processing
>            Reporter: Remko Popma
>            Priority: Major
>
> This ticket proposes to replace commons-cli with picocli in 
> {{groovy.util.CliBuilder}}.
> See [discussion on the mailing 
> list|https://lists.apache.org/thread.html/d60b6d5d4411e9ba0d7dc209cde8a9bb4abb00f0b9c0322f068c322e@%3Cdev.groovy.apache.org%3E]
>  for the original proposal and comparison with other CLI libraries.
> Goals for the initial implementation:
> * preserve the current CliBuilder behaviour as much as possible
> * deliver an implementation, tests and documentation in time to be included 
> in the 2.5 GA release



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to