Attribute 'requiredOptionMarker' should have type 'java.lang.Character'; but found type 'java.lang.String'

41 views Asked by At

Running Script FAILS with Groovy 3.0.19 but PASSES with Groovy 4.0.15

I'm trying to follow picocli documentation instructions specific to groovy scripts : Section 30.1.2. Groovy Scripts

There is a particular annotation named Command that has a requiredOptionMarker attribute. See section 14.4.4. Required-Option Marker requiredOptionMarker accepts a char.

In my script when I try to assign '*' to requiredOptionMarker my script fails to compile.

@Command(name = "sampleScript",
        mixinStandardHelpOptions = true,
        requiredOptionMarker = '*')

I get error :

Attribute 'requiredOptionMarker' should have type 'java.lang.Character'; but found type 'java.lang.String' in @picocli.CommandLine$Command
 @ line 63, column 32.
           requiredOptionMarker = '*',
                                  ^

1 error

Tried various suggestions like (char) '*' , '*' as char. Nothing seems to work.

While searching for it the closest I got to is this jira ticket GROOVY-3278

Any help is greatly appreciated.

EDIT 1 : START

Just in case any wants to play around, I have a MCVE at

https://github.com/akmalick/sample-picocli/blob/requiredOptionMarker/sample-picocli.groovy

The master branch contains script that will PASS

The requiredOptionMarker branch contains the script that recreates the issue and FAILS as it contains the requiredOptionMarker = '*' change.

EDIT 1 : END

EDIT 2 : START

After taking care of the comma as in

sortOptions = false,
    requiredOptionMarker = ((char)'*') //---->>>>> This DOES"T WORK

running without compile tatic I get something like this

>groovy sample-picocli.groovy

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\ws\sample-picocli.groovy: 35: Expected '(char) *' to be an inline constant of type char in @picocli.CommandLine$Command
 @ line 35, column 32.
           requiredOptionMarker = ((char)'*') //---->>>>> This DOES"T WORK
                                  ^

C:\ws\picocli\sample-picocli.groovy: 35: Attribute 'requiredOptionMarker' should have type 'java.lang.Character'; but found type 'java.lang.Object' in @picocli.CommandLine$Command
 @ line 35, column 32.
           requiredOptionMarker = ((char)'*') //---->>>>> This DOES"T WORK
                                  ^

C:\ws\picocli\sample-picocli.groovy: 35: Expected '(char) *' to be an inline constant of type char in @picocli.CommandLine$Command
 @ line 35, column 32.
           requiredOptionMarker = ((char)'*') //---->>>>> This DOES"T WORK
                                  ^

C:\ws\picocli\sample-picocli.groovy: 35: Attribute 'requiredOptionMarker' should have type 'java.lang.Character'; but found type 'java.lang.Object' in @picocli.CommandLine$Command
 @ line 35, column 32.
           requiredOptionMarker = ((char)'*') //---->>>>> This DOES"T WORK
                                  ^

4 errors

EDIT 2 : END

1

There are 1 answers

3
Remko Popma On

Did you try the solution presented here? https://stackoverflow.com/a/33020020/1446916

Basically do a hard cast in your script:

@Command(
       …
    requiredOptionMarker = ((char) '*'))

Note that you need brackets around the whole thing: ((char) '*'), just (char) '*' may not work.