Skip to content

Instantly share code, notes, and snippets.

@wspeirs
Created January 18, 2013 23:11
Show Gist options
  • Save wspeirs/4569478 to your computer and use it in GitHub Desktop.
Save wspeirs/4569478 to your computer and use it in GitHub Desktop.
// 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")) {
System.out.println("Found opt!");
}
// get -D options and their values
if(cmdLine.hasOption("D")) {
Properties props = cmdLine.getOptionProperties("D");
for(Entry<Object, Object> entry:props.entrySet()) {
System.out.println("Property: " + entry.getKey() + " " + entry.getValue());
}
}
// see if we have a file option by checking it's value
String file = null;
if(null != (file = cmdLine.getOptionValue("file")) ) {
System.out.println("File option: " + file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment