use of org.apache.commons.cli.UnrecognizedOptionException in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsMergerMain method run.
/*****************************************************************************
* {@link Runnable} Interface
****************************************************************************/
public void run(String[] args) throws IOException {
if (needsHelp(args)) {
printHelp();
System.exit(0);
}
try {
CommandLine cli = _parser.parse(_options, args, true);
runApplication(cli, args);
} catch (MissingOptionException ex) {
System.err.println("Missing argument: " + ex.getMessage());
printHelp();
} catch (MissingArgumentException ex) {
System.err.println("Missing argument: " + ex.getMessage());
printHelp();
} catch (UnrecognizedOptionException ex) {
System.err.println("Unknown argument: " + ex.getMessage());
printHelp();
} catch (AlreadySelectedException ex) {
System.err.println("Argument already selected: " + ex.getMessage());
printHelp();
} catch (ParseException ex) {
System.err.println(ex.getMessage());
printHelp();
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.apache.commons.cli.UnrecognizedOptionException in project zm-mailbox by Zimbra.
the class ItemDataFile method main.
public static void main(String[] args) {
String cset = null;
Options opts = new Options();
CommandLineParser parser = new GnuParser();
opts.addOption("a", "assemble", false, "assemble backup");
opts.addOption("c", "charset", true, "path charset");
opts.addOption("e", "extract", false, "extract backup");
opts.addOption("h", "help", false, "help");
opts.addOption("l", "list", false, "list backup");
opts.addOption("n", "nometa", false, "ignore metadata");
opts.addOption("p", "path", true, "extracted backup path");
opts.addOption("t", "types", true, "item types");
ZimbraLog.toolSetupLog4j("ERROR", null);
try {
CommandLine cl = parser.parse(opts, args);
String path = ".";
String file = null;
boolean meta = true;
Set<MailItem.Type> types = null;
if (cl.hasOption('c')) {
cset = cl.getOptionValue('c');
}
if (cl.hasOption('n')) {
meta = false;
}
if (cl.hasOption('p')) {
path = cl.getOptionValue('p');
}
if (cl.hasOption('t')) {
try {
types = MailItem.Type.setOf(cl.getOptionValue('t'));
} catch (IllegalArgumentException e) {
throw MailServiceException.INVALID_TYPE(e.getMessage());
}
}
if (cl.hasOption('h') || cl.getArgs().length != 1) {
usage(opts);
}
file = cl.getArgs()[0];
if (cl.hasOption('a')) {
create(path, types, cset, new FileOutputStream(file));
} else if (cl.hasOption('e')) {
extract(new FileInputStream(file), meta, types, cset, path);
} else if (cl.hasOption('l')) {
list(file.equals("-") ? System.in : new FileInputStream(file), types, cset, System.out);
} else {
usage(opts);
}
} catch (Exception e) {
if (e instanceof UnrecognizedOptionException)
usage(opts);
else
e.printStackTrace(System.out);
System.exit(1);
}
}
Aggregations