You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Alan Hengle (JIRA)" <ji...@apache.org> on 2017/08/31 22:53:00 UTC
[jira] [Updated] (GROOVY-8307) CliBuilder problem with
multi-argument option if last
[ https://issues.apache.org/jira/browse/GROOVY-8307?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alan Hengle updated GROOVY-8307:
--------------------------------
Description:
When a multi-argument option is passed as the last option, any arguments after that get absorbed into it. As you can see from the code and examples below, inserting a no-argument option in between the -m and the parsed arguments causes the problem to go away.
{code:java}
import org.apache.commons.cli.Option
CliBuilder cli = new CliBuilder(usage:"example of using multi-arg value")
cli.with {
m(longOpt:'multiple-opts', args: Option.UNLIMITED_VALUES, valueSeparator: ';',
"enter multiple values, separated by ';' (usage: -mval1;val2)")
a(longOpt:'simple-arg', "simple argument")
h("help")
}
// cli.stopAtNonOption can be true or false, same result
def opts = cli.parse(args)
if (opts.m)
opts.ms.eachWithIndex { l,i -> println "$i: $l" }
println "arguments: ${opts.arguments()}"
{code}
Usage:
{code:java}
> groovy clibuilderError.groovy "-mhello;goodbye" arg1 arg2 arg3
0: hello
1: goodbye
2: arg1
3: --
4: arg2
5: arg3
arguments: []
> groovy clibuilderError.groovy "-mhello;goodbye" -a arg1 arg2 arg3
0: hello
1: goodbye
arguments: [arg1, arg2, arg3]
{code}
was:
When a multi-argument option is passed as the last option, any arguments after that get absorbed into it. As you can see from the cod and examples below, inserting a no-argument option in between the -m and the parsed arguments causes the problem to go away.
{code:java}
import org.apache.commons.cli.Option
CliBuilder cli = new CliBuilder(usage:"example of using multi-arg value")
cli.with {
m(longOpt:'multiple-opts', args: Option.UNLIMITED_VALUES, valueSeparator: ';',
"enter multiple values, separated by ';' (usage: -mval1;val2)")
a(longOpt:'simple-arg', "simple argument")
h("help")
}
// cli.stopAtNonOption can be true or false, same result
def opts = cli.parse(args)
if (opts.m)
opts.ms.eachWithIndex { l,i -> println "$i: $l" }
println "arguments: ${opts.arguments()}"
{code}
Usage:
{code:java}
> groovy clibuilderError.groovy "-mhello;goodbye" arg1 arg2 arg3
0: hello
1: goodbye
2: arg1
3: --
4: arg2
5: arg3
arguments: []
> groovy clibuilderError.groovy "-mhello;goodbye" -a arg1 arg2 arg3
0: hello
1: goodbye
arguments: [arg1, arg2, arg3]
1
{code}
> CliBuilder problem with multi-argument option if last
> -----------------------------------------------------
>
> Key: GROOVY-8307
> URL: https://issues.apache.org/jira/browse/GROOVY-8307
> Project: Groovy
> Issue Type: Bug
> Components: groovy-jdk
> Affects Versions: 2.4.12
> Environment: Ubuntu 15.04
> JVM 1.8.0.121 (Oracle)
> Reporter: Alan Hengle
>
> When a multi-argument option is passed as the last option, any arguments after that get absorbed into it. As you can see from the code and examples below, inserting a no-argument option in between the -m and the parsed arguments causes the problem to go away.
> {code:java}
> import org.apache.commons.cli.Option
> CliBuilder cli = new CliBuilder(usage:"example of using multi-arg value")
> cli.with {
> m(longOpt:'multiple-opts', args: Option.UNLIMITED_VALUES, valueSeparator: ';',
> "enter multiple values, separated by ';' (usage: -mval1;val2)")
> a(longOpt:'simple-arg', "simple argument")
> h("help")
> }
> // cli.stopAtNonOption can be true or false, same result
> def opts = cli.parse(args)
> if (opts.m)
> opts.ms.eachWithIndex { l,i -> println "$i: $l" }
> println "arguments: ${opts.arguments()}"
> {code}
> Usage:
> {code:java}
> > groovy clibuilderError.groovy "-mhello;goodbye" arg1 arg2 arg3
> 0: hello
> 1: goodbye
> 2: arg1
> 3: --
> 4: arg2
> 5: arg3
> arguments: []
> > groovy clibuilderError.groovy "-mhello;goodbye" -a arg1 arg2 arg3
> 0: hello
> 1: goodbye
> arguments: [arg1, arg2, arg3]
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)