Search in sources :

Example 6 with UnrecognizedOptionException

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();
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) ParseException(org.apache.commons.cli.ParseException) MissingOptionException(org.apache.commons.cli.MissingOptionException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) IOException(java.io.IOException) MissingOptionException(org.apache.commons.cli.MissingOptionException) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) ParseException(org.apache.commons.cli.ParseException) MissingArgumentException(org.apache.commons.cli.MissingArgumentException)

Example 7 with UnrecognizedOptionException

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);
    }
}
Also used : Options(org.apache.commons.cli.Options) GnuParser(org.apache.commons.cli.GnuParser) FileInputStream(java.io.FileInputStream) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) CommandLine(org.apache.commons.cli.CommandLine) FileOutputStream(java.io.FileOutputStream) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Aggregations

UnrecognizedOptionException (org.apache.commons.cli.UnrecognizedOptionException)7 CommandLine (org.apache.commons.cli.CommandLine)6 IOException (java.io.IOException)5 CommandLineParser (org.apache.commons.cli.CommandLineParser)4 File (java.io.File)3 GnuParser (org.apache.commons.cli.GnuParser)3 MissingOptionException (org.apache.commons.cli.MissingOptionException)3 Options (org.apache.commons.cli.Options)3 ParseException (org.apache.commons.cli.ParseException)3 FileInputStream (java.io.FileInputStream)2 AlreadySelectedException (org.apache.commons.cli.AlreadySelectedException)2 MissingArgumentException (org.apache.commons.cli.MissingArgumentException)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)1 CoverageGenerator (com.github.timurstrekalov.saga.core.CoverageGenerator)1 Config (com.github.timurstrekalov.saga.core.cfg.Config)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 RandomAccessFile (java.io.RandomAccessFile)1