clibuilder

#!/usr/bin/env groovy
 
/* 
 *  Script: argumentsCliBuilder.groovy
 *
 * Purpose: <+purpose+>
 *
 *   Usage: groovy argumentsCliBuilder.groovy <+usage+> 
 *
 *  Author: <+author+>
 */
 
// Parse command line arguments
def cli = new CliBuilder(usage: 'groovy argumentsCliBuilder.groovy [-h|--help] [ -t "times" ] [[ -f "file1" ]..]',
                         parser: new org.apache.commons.cli.GnuParser ())
 
cli.h(longOpt:'help', 'show usage information and quit')
cli.t(argName:'times', args:1, required:false, 'Number of X to create')
cli.f(argName:'file', args:1, required:false, 'File name(s) of e-mail templates to use for Incidents')
 
// To actually parse the command line options, use the following command.
def opt = cli.parse(args)
 
// cli.parse will have already printed the usage if a required param is missing.
// All we have to do is exit if !opt
if (!opt) return
if (opt.h) {
    cli.usage() 
    return 0
}
 
// Default to 1 optTimes
def optTimes = (opt.t) ? opt.t : 1
// Default to a list
def optFiles = opt.f ? opt.fs : [ 'defaultFileName' ]
 
optFiles.each {
    println it
}
 
 
// Print the remaining un-option style arguments.
// Example, the "foo bar" in this commmand line:  soemthing.groovy --option1 dee --verbose foo bar
def arguments = opt.arguments()
if (arguments[0]) {
    print "1st arg is: ${arguments[0]}"
}

See Also

Related Pages on Notesmine

PageDescriptionTags
clibuilder #!/usr/bin/env groovy /* * Script: argumentsCliBuilder.groovy * * Purpose: <+purpose+> * * Usage: groovy argumentsCliBuilder.groovy <+usage+> * * …

External Pages

No bookmarks tagged clibuilder

 
clibuilder.txt · Last modified: 2009/07/15 11_08 by tookelso
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki