Skip to content

Instantly share code, notes, and snippets.

// check to see if they need help
// notice we only use the short-version, but it checks both!
if(cmdLine.hasOption("h")) {
new HelpFormatter().printHelp("sop4j-cli", options);
return;
}
// check to see if they passed in an opt
// recommended to use the long version as it's more readable
if(cmdLine.hasOption("opt")) {
@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;