software_writer
software_writer

Reputation: 4478

CliBuilder not reading past first argument

I am trying to write a groovy script which uses CliBuilder to read command line arguments. Here's my code

def cli = new CliBuilder(usage:'groovy -s "server name" -r "file name"')
cli.s('Name of the server', required: true)
cli.r('Name of the file', required: true)

def args = ['-s', 'ServerEx', '-r', 'RakeEx']
def opt = cli.parse(args)

when I run this script, it gives me error Missing required option: r even though I have provided the argument r.

I searched for the solution but I found reading multiple arguments for the same flags,

eg. -s arg1 arg2, but not reading multiple arguments for different flags.

Any help is really appreciated. Thank you.

Upvotes: 0

Views: 254

Answers (1)

software_writer
software_writer

Reputation: 4478

Well, as it turns out, I have to specify the args:1 as a property when defining flags. I just found this from this article from Javaworld: http://www.javaworld.com/article/2073443/explicitly-specifying--args--property-with-groovy-clibuilder.html

Also, as an added bonus, now I can directly access the value provided by using opt.r. It used to show boolean true/false before adding args:1

Upvotes: 1

Related Questions