Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 988
jomaora Avatar asked Jul 26 '11 15:07

jomaora


1 Answers

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]
like image 84
tim_yates Avatar answered Nov 13 '22 23:11

tim_yates