Skip to content

Instantly share code, notes, and snippets.

@jpertino
Created December 30, 2010 14:32
Show Gist options
  • Save jpertino/759840 to your computer and use it in GitHub Desktop.
Save jpertino/759840 to your computer and use it in GitHub Desktop.
groovy CliBuilder usage
def cli = new CliBuilder().with {
usage = 'program [options] <arguments>'
header = 'Options:'
footer = '-' * width
s 'simplest boolean option'
b longOpt: 'both', 'boolean option with both longop and shortop'
_ longOpt: 'no-shortop-1', 'boolean option without short version 1'
_ longOpt: 'no-shortop-2', 'boolean option without short version 2'
n args:1, argName:'thing', 'simple argument option'
r args:1, argName:'thing', 'required argument option', required: true
u args:2, 'key value argument option, no clue'
v args:2, argName:'property=value', valueSeparator:'=', 'key=value argument option'
parse(args) ?: System.exit(1)
}
// -b --no-shortop-1 -r req -u vvv www -v xxx=yyy qwer asdf "1234 5678" zxcv cvbn
println 'Arguments: ' << cli.arguments()
println '-s: ' << cli.s
println '-b: ' << cli.b
println '--no-shortop-1: ' << cli.'no-shortop-1'
println '--no-shortop-2: ' << cli.'no-shortop-2'
println '-n: ' << cli.n
println '-r: ' << cli.r
println '-u: ' << cli.us
println '-v: ' << cli.vs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment