groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nelson, Erick" <Erick.Nel...@hdsupply.com>
Subject does 2.5 break CliBuilder?
Date Fri, 25 May 2018 16:59:40 GMT
Caught: groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: opt for class:
org.apache.commons.cli.Option

groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: opt for class: org.apache.commons.cli.Option

       at script.Cli.createOption(Cli.groovy:158)

       at script.Cli.createDefaultOptions(Cli.groovy:88)

       at script.Cli.<init>(Cli.groovy:29)

       at test_cli.run(test_cli.groovy:6)

I see that it upgrades from commons-cli 1.2 to 1.4

Code snippet…
I’m dynamically trying to build default command line options for my scripting framework.
This works in 2.4

        // validate the option
        Integer slen = map.opt.length() // short opt length
        Integer llen = map.longOpt.length() // long opt length
        if (slen > 1 || llen == 1 || (slen == 0 && llen == 0)) {
            log.warn "invalid cli opt definition [$config]"
            return
        }
        if (slen) {
            if (builder.options.getOption(map.opt)) {
                log.warn "opt already used [$config]"
                return
            }
        }
        if (llen) {
            if (builder.options.getOption(map.longOpt)) {
                log.warn "longOpt already used [$config]"
                return
            }
        }
        // add the option
        Map builderOption = [:]
        if (llen > 0) {
            builderOption.longOpt = map.longOpt
        }
        if (slen > 0) {
            builderOption.opt = map.opt
        }
        if (map.argName) {
            builderOption.args = 1
            builderOption.argName = map.argName
        }
        builder."${map.opt ?: '_'}"(builderOption, map.desc)  // problem is here



Mime
View raw message