jomaora
jomaora

Reputation: 1656

What does 'args' means on CliBuilder?

I'm a newbie on Groovy and I'm trying to understand what's the meaning of args attribute on CliBuilder. I'm not sure if it means the max number of parameters that an option can take.

I have something like

import java.text.*

def test(args) {
def cli = new CliBuilder(usage: 'test.groovy brand instance')
    cli.with {
        h longOpt: 'help', 'Show usage information'
    }

    cli.b(argName:'brand', args: 1, required: true, 'brand name')
    cli.p(argName:'ports', args: 2, required: true, 'ports')

    def options = cli.parse(args)
    if (!options) {
           return
    }

    if (options.h) {
            cli.usage()
            return
    }

    println options.b
    println options.p

}

test(args)

When I call the script I use groovy test.groovy -b toto -p 10 11

But I get:

toto
10

Shouldn't I get 10 11 for the -p option? If not, what does args mean?

Thanks

Upvotes: 5

Views: 783

Answers (1)

tim_yates
tim_yates

Reputation: 171154

This post here should explain how the args parameter works

Basically, you need to add a plural s to your println line like so:

println options.bs

That should then print:

[10, 11]

Upvotes: 6

Related Questions