groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <>
Subject new GroovyCliBuilder
Date Fri, 24 May 2019 17:11:49 GMT
Hi guys,

just wanted to say that I recently had to revisit some older Groovy script code in my project,
and I took the opportunity to switch the old CliBuilder implementation to the new Picocli
based one (
) - and I can just say that it is an absolute joy to work with: Concise, elegant, and type
safe G-)

import groovy.cli.commons.CliBuilder
import groovy.cli.Option
import groovy.cli.Unparsed

// Alternative is to use an interface and let Groovy instantiate a class instance from it
class MyOptions {
  boolean isTestRun
  @Option(shortName='h', description='output help info') Boolean help
  @Option(shortName='r', description='process regular entries') Boolean regular
  // etc (for supported types outside of Boolean see URL above)
  @Unparsed List remaining // all additional options given

  MyScriptOptions(boolean isTestRun) { this.isTestRun = isTestRun }

final cli = new CliBuilder(usage:'my_powerful_groovy_script')
def opts = new MyOptions(true)
cli.parseFromInstance(opts, args.split())  // From now on all cmd line 
params can be accessed in a type safe manner

if( {
   println cli.usage()

if(opts.regular) {


View raw message