You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Brian Ray (JIRA)" <ji...@apache.org> on 2019/05/08 14:20:00 UTC

[jira] [Commented] (GROOVY-9016) picocli-based CliBuilder can be tricked into greedily consuming option as an arg

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

Brian Ray commented on GROOVY-9016:
-----------------------------------

When I submitted this issue I believed that the introduction of picocli included switching {{groovy.util.CliBuilder}} to wrap picocli. After poking around some more I realized my mistake; this class [still wraps cli-commons|https://github.com/apache/groovy/blob/GROOVY_2_5_6/subprojects/groovy-cli-commons/src/main/groovy/groovy/util/CliBuilder.groovy#L21].

Since the class is deprecated, this could be a very minor bug indeed.

I'll try to make some time to run tests against the recommended {{groovy.cli.picocli.CliBuilder}} and {{groovy.cli.commons.CliBuilder}}.

> picocli-based CliBuilder can be tricked into greedily consuming option as an arg
> --------------------------------------------------------------------------------
>
>                 Key: GROOVY-9016
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9016
>             Project: Groovy
>          Issue Type: Bug
>          Components: command line processing
>    Affects Versions: 2.5.6
>         Environment: >>First encountered<<
> Groovy 2.4.15 - no bug
> Groovy 2.5.6 - bug
> Win 8.1 Pro
> Zulu OpenJDK 1.8.0_202
> >>Minimal replication<<
> Groovy 2.4.8 (distro package) - no bug
> OpenJDK 1.8.0_181 (distro package)
> Debian 9/Stretch
> groovy:2.5.6-jre8-alpine Docker image - bug
> OpenJdk 1.8.0_191 (in image)
> Debian 9/Stretch + Alpine 8 (in image)
>            Reporter: Brian Ray
>            Assignee: Remko Popma
>            Priority: Minor
>
> Stumbled across this edge case upgrading from 2.4.x to 2.5.6. Given the following {{CliBuilder}} based script,
> {code:java}
> final cli = new CliBuilder()
> cli.with {
>   f(
>     longOpt: "firstOpt",
>     "first option",
>     required: false,
>     args: 1,
>     argName: "firstOpt",
>   )
> }
> final opts = cli.parse(args)
> println """
>   firstOpt=$opts.firstOpt
>   args=${ opts.arguments() }
> """
> {code}
> Passing an option value containing the character combo {{+=}} can trigger greedy assignment to args. Here is the pre-2.5 behavior.
> {noformat}
> $ ~/cli_greedy_arg.groovy -f+= bat
>   firstOpt=+=
>   args=[bat]
> $ ~/cli_greedy_arg.groovy -f'+=' bat
>   firstOpt=+=
>   args=[bat]
> $ ~/cli_greedy_arg.groovy -f"+=" bat
>   firstOpt=+=
>   args=[bat]
> $ ~/cli_greedy_arg.groovy -f="+=" bat
>   firstOpt==+=
>   args=[bat]
> {noformat}
> That odd option value is captured properly each time.
> Bumping up to 2.5.6 that option value tricks picocli (I'm guessing) into consuming the opt value as an arg in three out of four attempts.
> {noformat}
> $ docker run --rm -v "$PWD":/home/groovy/scripts -w /home/groovy/scripts groovy:2.5.6-jre8
> -alpine groovy cli_greedy_arg.groovy -f+= bat
>   firstOpt=false
>   args=[-f+=, bat]
> $ docker run --rm -v "$PWD":/home/groovy/scripts -w /home/groovy/scripts groovy:2.5.6-jre8
> -alpine groovy cli_greedy_arg.groovy -f'+=' bat
>   firstOpt=false
>   args=[-f+=, bat]
> $ docker run --rm -v "$PWD":/home/groovy/scripts -w /home/groovy/scripts groovy:2.5.6-jre8
> -alpine groovy cli_greedy_arg.groovy -f"+=" bat
>   firstOpt=false
>   args=[-f+=, bat]
> $ docker run --rm -v "$PWD":/home/groovy/scripts -w /home/groovy/scripts groovy:2.5.6-jre8
> -alpine groovy cli_greedy_arg.groovy -f="+=" bat
>   firstOpt=+=
>   args=[bat]
> {noformat}
>  



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