HOWTO: Handling Command line Arguments in a Groovy Script

println "Started Groovy Script"
 println "All args Received : "
 println args
className = getClass().simpleName
 def cli = new CliBuilder(usage: "groovy ${className}.groovy -h HOSTNAME -u USERNAME -p PASSWORD -pt PROCESSTYPEURI -a INPUTANALYTELIMSID")
 cli.u(argName:'username', longOpt:'username', required:true, args:1, 'LIMS username (Required)')
 cli.p(argName:'password', longOpt:'password', required:true, args:1, 'LIMS password (Required)')
 cli.pt(argName:'processTypeURI', longOpt:'processTypeURI', required:true, args:1, 'The Uri of the process used in process (Required)')
def opt = cli.parse(args)
 if (!opt) {
 println "Aborted Groovy Script"
 System.exit(-1)
 }
 hostname = opt.h
 username = opt.u
 password = opt.p
 processTypeURI = opt.pt
 inputAnalyeLIMSID = opt.a

See : https://gist.github.com/gkowalski/5599595

Advertisements