groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shil Sinha <shil.si...@gmail.com>
Subject Re: CliBuilder enhancements
Date Sat, 09 Apr 2016 20:50:26 GMT
Did a quick review of the tests and documentation, looks great! This is a
feature I'll definitely be using upon its availability.

On Sat, Apr 9, 2016 at 8:04 AM, Paul King <paulk@asert.com.au> wrote:

> 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
> CliBuilder.
> The results can be found here:
>
> https://github.com/apache/groovy/pull/308
>
> 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.
>

Mime
View raw message