Skip to content

Instantly share code, notes, and snippets.

@luismoramedina
Last active July 22, 2016 16:28
Show Gist options
  • Save luismoramedina/eb79276626238b9a461ac1df2e409050 to your computer and use it in GitHub Desktop.
Save luismoramedina/eb79276626238b9a461ac1df2e409050 to your computer and use it in GitHub Desktop.
Groovy argument parse
#!/usr/bin/env groovy
def cli = new CliBuilder(usage: 'cli', stopAtNonOption: false)
cli.n('Force numeric on property set')
cli.h(longOpt: 'help', 'Show usage information')
cli.c(longOpt: 'config-server', args:1, argName:'server', 'Config server url')
cli.p(longOpt: 'profile', args:1, argName:'profile', 'Profile')
cli.l(longOpt: 'label', args:1, argName:'label', 'Label')
cli.u(longOpt: 'credentials', args:1, argName:'user:pass', 'Basic credentials')
def options = cli.parse(args)
if (args.length == 0 || options.h) {
cli.usage()
return
}
println "arguments: " + options.arguments()
println "n: " + options.n
println "c: " + options.c
println "p: " + options.p
println "l: " + options.l
println options.arguments()[0]
println options.arguments()[1].split('=')[0]
println options.arguments()[1].split('=')[1]
println options.u.split(':')[0]
println options.u.split(':')[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment