I use CliBuilderto parse the command line arguments for the Groovy script. Among the arguments that I have identified, I have one that is mandatory. Is there a way to support an argument -h,--helpthat will print using the command without annoying error messages regarding missing arguments?
For example, run the following Groovy script with only an argument -h:
def cli = new CliBuilder (usage:'test', stopAtNonOption:false)
cli.r (longOpt:'required', required:true, 'Required argument.')
cli.h (longOpt:'help', 'Prints this message')
def options = cli.parse (args)
will generate the output below when it hits the line def options = cli.parse (args), and will automatically stop the script from executing:
error: Missing required option: r
usage: test
-h, - help Prints this message
-r, - required Required argument.
, -h --help, required:true . ?