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

CliBuilder problem with multi-argument option if last

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.12
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
      None
    • Environment:
      Ubuntu 15.04
      JVM 1.8.0.121 (Oracle)

      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.

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

      Usage:

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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ahengle Alan Hengle
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: