groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <>
Subject [jira] [Commented] (GROOVY-8520) Replace commons-cli with picocli in CliBuilder
Date Mon, 16 Apr 2018 16:25:00 GMT


Remko Popma commented on GROOVY-8520:

I now believe the remaining failing test is really the result of an idiosyncrasy in commons-cli:

When a parameter is attached to the short option (e.g. {{-a1}}), the value of {{args}} is
ignored. No validation error like "error: Missing argument for option: a" ever occurs.

To illustrate:
// using GROOVY_2_5_X branch: CliBuilder based on commons-cli
def cli = new CliBuilder()
cli.a(args: 2, 'arguments')

assertNull(cli.parse(['-a', '1'])) // as expected: '-a' option needs 2 params

options = cli.parse(['-a1']) // I would expect parsing to fail, but it succeeds.
assertEquals('1', options.a) // Why is 1 option-param okay here? 

assertNull(cli.parse(['-a', '1', '-a', '2'])) // as expected: each '-a' option needs 2 params

options = cli.parse(['-a1', '-a2'])
assertEquals('1', options.a) // similar to preceding; why does this succeed?... 
assertEquals(['1', '2'],

options = cli.parse(['-a1', '-a2', '-a3'])
assertEquals(['1', '2', '3'], // even this is okay...

Is this behaviour desirable? If so, I can add an option to picocli to ignore arity for attached
option-arguments. Do we want to support this behaviour?

While adding more tests, another behaviour I noticed that I found strange is this:
def cli = new CliBuilder()
cli.b(args: 2, valueSeparator: ',', 'arguments')
options = cli.parse(['-b1,2,3'])

assert == ['1', '2']
       |       |  |
       |       |  false
       |       ['1', '2,3']
I would expect the parser to split first, and then to validate the result. It looks like,
counter to my expectations, common-cli stops splitting when the input has been split into
{{args}} chunks. The last chunk may still contain the value separator character.

Again, is this behaviour desirable, and should it be supported?

> Replace commons-cli with picocli in CliBuilder
> ----------------------------------------------
>                 Key: GROOVY-8520
>                 URL:
>             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|]
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

View raw message