Friday, 15 February 2013

groovy - CliBuilder Arguments Are Empty -



groovy - CliBuilder Arguments Are Empty -

here's working illustration of problem:

def cli = new clibuilder(usage: 'cli-test -d <argument>') cli.with { h(longopt: 'help', 'usage information') d(longopt: 'do-something', required: true, args: 1, 'do something' ) } optionaccessor options = cli.parse(args) if(!options) { homecoming } // print usage if -h, --help, or no argument given if(options.h || options.arguments().isempty()) { println options.arguments().size() cli.usage() homecoming } else if (options.d) { println options.d }

when execute script following:

groovy cli-test.groovy -d hello

i output:

0 usage: cli-test -d <argument> -d,--do-something <arg> -h,--help usage info

the 0 println arguments length. can't options work other h. i'm not sure if i'm doing wrong.

the reason there no arguments! you've swallowed them in options.

if call

groovy cli-test.groovy -d hello foo

then arguments() list [foo]

the -d arg automatically checked because made required, there's no need test later on.

groovy command-line-interface

No comments:

Post a Comment