groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <>
Subject CliBuilder enhancements
Date Sat, 09 Apr 2016 12:04:08 GMT
Hi everyone,

More than a year ago, Jim White and myself worked on some possible
enhancements to CliBuilder. At the time Jim was mostly trying to add
support for JCommander to allow annotation style CLI usage patterns
and I was trying to work out a nice way to allow us to swap in
different CLI packages underneath CliBuilder. To cut a long story
short, we never finished those spikes, so I grabbed a subset of the
ideas and did a minimal change to allow annotation support with
The results can be found here:

The tests and doco give all the details but as a sneak peek, if you
define this option specification:

interface GreeterI {
  @Option(shortName='h', description='display usage') Boolean help()
  @Option(shortName='a', description='greeting audience') String audience()
  @Unparsed List remaining()

You can then use CliBuilder as follows:

def cli = new CliBuilder(usage: 'groovy Greeter [option]')
def argz = '--audience Groovologist'.split()
def options = cli.parseFromSpec(GreeterI, argz)
assert options.audience() == 'Groovologist'

There are numerous ways to define the option specification and
numerous other features which are covered in the doco and tests but
hopefully this will give the idea.

Any feedback/comments welcome.

Cheers, Paul.

View raw message