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

CLIBuilder: "error: Missing required options" when unknown options are provided

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.2
    • Fix Version/s: 3.0.4, 2.5.12
    • Labels:
      None
    • Environment:
      Linux/Windows

      Description

      When passing an additional option to a script that doesn't know about this option, I get an error message about "missing required options", listing all required options that follow the unkown option.

      The following example code reproduces the issue:

      @Grab('info.picocli:picocli-groovy:4.2.0')
      @GrabConfig(systemClassLoader=true)
      
      import groovy.cli.picocli.CliBuilder
      
      def cli = new CliBuilder(name: 'cliTest.groovy')
      cli.h(type: Boolean, longOpt: 'help', usageHelp: true, required: false, 'Show usage information')
      cli.a(type: String, longOpt: 'optA', required: true, args: 1, 'Option a (required)')
      cli.b(type: String, longOpt: 'optB', required: true, args: 1, 'Option b (required)')
      // NOTE: No "-c|--optC" here
      cli.d(type: String, longOpt: 'optD', required: true, args: 1, 'Option d (required)')
      cli.e(type: String, longOpt: 'optE', required: true, args: 1, 'Option e (required)')
      cli.f(type: String, longOpt: 'optF', required: false, args: 1, 'Option f (optional)')
      def opts = cli.parse(args)
      opts || System.exit(1)
      if(opts.h) {
        cli.usage()
        System.exit(0)
      }

      When invoked with an additional option, '-c C' for example, it produces the following, misleading output:

      % ~/tmp/groovy-3.0.2/bin/groovy ./cliTest.groovy -a A -b B -c C -d D -e E
      error: Missing required options [--optD=PARAM, --optE=PARAM]
      Usage: cliTest.groovy [-h] -a=PARAM -b=PARAM -d=PARAM -e=PARAM [-f=PARAM]
        -a, --optA=PARAM   Option a (required)
        -b, --optB=PARAM   Option b (required)
        -d, --optD=PARAM   Option d (required)
        -e, --optE=PARAM   Option e (required)
        -f, --optF=PARAM   Option f (optional)
        -h, --help         Show usage information

      The list of missing options varies depending on where "-c C" is inserted. There's no error when it's the last one.

      I would expect it to either ignore the addtional option in all cases or emit an error message about an unknown option. But in no case should it error out because of missing required options when there are none missing.

        Attachments

          Activity

            People

            • Assignee:
              rpopma Remko Popma
              Reporter:
              dheinric Dirk Heinrichs
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: