Skip to content

Instantly share code, notes, and snippets.

@wspeirs
wspeirs / BasicOptions2.java
Created January 18, 2013 23:03
Parsing a command line
final GnuParser parser = new GnuParser();
final Options options = configureOptions();
// parse with the parser
CommandLine cmdLine = null;
try {
cmdLine = parser.parse(options, args);
} catch(ParseException e) {
e.printStackTrace();
return;
@wspeirs
wspeirs / BasicOptions1.java
Created January 18, 2013 22:54
Methods for creation an Option
Options options = new Options();
// create the simple option without using the OptionBuilder
options.addOption("o", "opt", false, "An option, no args");
// simple help option using the builder
options.addOption(OptionBuilder.withLongOpt("help")
.create("h"));
// an option with a value separator, defaults to =