// Create a Parser
CommandLineParser parser = new BasicParser();
Options options = new Options();
options.addOption("h", "help", false, "Print this usage information");
options.addOption("v", "verbose", false, "Print out VERBOSE information" );
OptionGroup optionGroup = new OptionGroup();
optionGroup.addOption( OptionBuilder.hasArg(true).withArgName("file")
.withLongOpt("file").create('f") );
optionGroup.addOption( OptionBuilder.hasArg(true).withArgName("email")
.withLongOpt("email").create('m") );
options.addOptionGroup( optionGroup );
// Parse the program arguments
try {
CommandLine commandLine = parser.parse( options, args );
if( commandLine.hasOption('h") ) {
printUsage( options );
System.exit(0);
}
// ... do important stuff ...
} catch( Exception e ) {
System.out.println( "You provided bad program arguments!" );
printUsage( options );
System.exit(1);
}