Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9016

Deprecated CliBuilder can be tricked into greedily consuming option as an arg

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.5.6
    • None
    • None

    Description

      Stumbled across this edge case upgrading from 2.4.x to 2.5.6. Given the following CliBuilder based script,

      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() }
      """
      

      Passing an option value containing the character combo += can trigger greedy assignment to args. Here is the pre-2.5 behavior.

      $ ~/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]
      

      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.

      $ 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]
      

       

      Attachments

        Issue Links

          Activity

            People

              rpopma Remko Popma
              brianeray Brian Ray
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: