groovy 属性“requiredOptionMarker”应具有类型“java.lang. String”;但找到类型“java.lang.String”

ukqbszuj  于 6个月前  发布在  Java
关注(0)|答案(1)|浏览(66)

运行脚本Groovy 3.0.19中失败,但在Groovy 4.0.15中通过**
我试图遵循特定于groovy脚本的picocli文档说明:
有一个名为Command的注解具有requiredOptionMarker属性。参见第14.4.4节。已验证-Option Marker requiredOptionMarker接受char。
在我的脚本中,当我尝试将**"*"分配给requiredOptionMarker**时,我的脚本无法编译。

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

字符串
我得到错误:

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


尝试了各种建议,如(char) '*''*' as char.似乎没有工作.
在寻找它的时候,我得到的最接近的是这个吉拉票GROOVY-3278
任何帮助都非常感谢。

编辑1:开始

万一有人想玩,我有一个MCVE在
https://github.com/akmalick/sample-picocli/blob/requiredOptionMarker/sample-picocli.groovy
master分支包含将通过的脚本
requiredOptionMarker分支包含重新创建问题和FAILS的脚本,因为它包含requiredOptionMarker = '*'更改。

编辑1:结束
编辑2:开始

在处理好逗号之后,

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


运行时没有编译策略我得到这样的东西

>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

编辑2:结束

4jb9z9bj

4jb9z9bj1#

您是否尝试过此处提供的解决方案?https://stackoverflow.com/a/33020020/1446916
基本上在你的剧本中做一个硬演员:

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

字符串
请注意,您需要将整个内容括起来:((char) '*'),仅(char) '*'可能不起作用。

相关问题