You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Dirk Heinrichs (Jira)" <ji...@apache.org> on 2020/04/27 12:59:00 UTC

[jira] [Created] (GROOVY-9528) CLIBuilder: "error: Missing required options" when unknown options are provided

Dirk Heinrichs created GROOVY-9528:
--------------------------------------

             Summary: CLIBuilder: "error: Missing required options" when unknown options are provided
                 Key: GROOVY-9528
                 URL: https://issues.apache.org/jira/browse/GROOVY-9528
             Project: Groovy
          Issue Type: Bug
          Components: command line processing
    Affects Versions: 3.0.2
            Reporter: Dirk Heinrichs


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:
{code:java}
@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)
}{code}
When invoked with an additional option, '-c C' for example, it produces the following, misleading output:
{code:java}
% ~/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{code}
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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)