Example usage for org.apache.commons.cli Options addOption

List of usage examples for org.apache.commons.cli Options addOption

Introduction

In this page you can find the example usage for org.apache.commons.cli Options addOption.

Prototype

public Options addOption(String opt, String longOpt, boolean hasArg, String description) 

Source Link

Document

Add an option that contains a short-name and a long-name.

Usage

From source file:at.salzburgresearch.vgi.vgianalyticsframework.activityanalysis.application.OsmHistoryImporter.java

public static void main(String[] args) {
    /**/*from ww w. ja va  2s .  c  o  m*/
     * Read input parameter
     */
    Options options = new Options();
    options.addOption("h", "help", false, "Display this help page");
    /** Settings */
    options.addOption(Option.builder("s").longOpt("settings").hasArg().argName("settings_file")
            .desc("settings file").build());
    options.addOption(Option.builder("p").longOpt("polygons").hasArg().argName("polygon_file")
            .desc("polygon file").build());
    /** OSM History importer */
    options.addOption(Option.builder("o").longOpt("osm").hasArg().argName("osm_history_file")
            .desc("osm history file").build());

    launch(options, args);
}

From source file:edu.msu.cme.rdp.readseq.ToFasta.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("m", "mask", true, "Mask sequence name indicating columns to drop");
    String maskSeqid = null;/*from ww  w  . j a  v a  2  s .  c o m*/

    try {
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("mask")) {
            maskSeqid = line.getOptionValue("mask");
        }

        args = line.getArgs();
        if (args.length == 0) {
            throw new Exception("");
        }

    } catch (Exception e) {
        new HelpFormatter().printHelp("USAGE: to-fasta <input-file>", options);
        System.err.println("ERROR: " + e.getMessage());
        System.exit(1);
        return;
    }

    SeqReader reader = null;

    FastaWriter out = new FastaWriter(System.out);
    Sequence seq;
    int totalSeqs = 0;
    long totalTime = System.currentTimeMillis();

    for (String fname : args) {
        if (fname.equals("-")) {
            reader = new SequenceReader(System.in);
        } else {
            File seqFile = new File(fname);

            if (maskSeqid == null) {
                reader = new SequenceReader(seqFile);
            } else {
                reader = new IndexedSeqReader(seqFile, maskSeqid);
            }
        }

        long startTime = System.currentTimeMillis();
        int thisFileTotalSeqs = 0;
        while ((seq = reader.readNextSequence()) != null) {
            out.writeSeq(seq.getSeqName().replace(" ", "_"), seq.getDesc(), seq.getSeqString());
            thisFileTotalSeqs++;
        }
        totalSeqs += thisFileTotalSeqs;
        System.err.println("Converted " + thisFileTotalSeqs + " (total sequences: " + totalSeqs
                + ") sequences from " + fname + " (" + reader.getFormat() + ") to fasta in "
                + (System.currentTimeMillis() - startTime) / 1000 + " s");
    }
    System.err.println("Converted " + totalSeqs + " to fasta in "
            + (System.currentTimeMillis() - totalTime) / 1000 + " s");

    out.close();
}

From source file:net.ladenthin.snowman.imager.run.CLI.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    try {/*ww  w .ja  v  a 2s  .c  om*/
        CommandLineParser parser = new PosixParser();
        Options options = new Options();

        options.addOption(cmdHelpS, cmdHelp, false, cmdHelpD);
        options.addOption(cmdVersionS, cmdVersion, false, cmdVersionD);

        options.addOption(OptionBuilder.withDescription(cmdConfigurationD).withLongOpt(cmdConfiguration)
                .hasArg().withArgName(cmdConfigurationA).create(cmdConfigurationS));

        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        final String cmdLineSyntax = "java -jar " + Imager.jarFilename;
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();

        final String configurationPath;
        if (line.hasOption(cmdConfiguration)) {
            configurationPath = line.getOptionValue(cmdConfiguration);
        } else {
            System.out.println("Need configuration value.");
            formatter.printHelp(cmdLineSyntax, options);
            return;
        }

        // check parameter
        if (args.length == 0 || line.hasOption(cmdHelp)) {
            formatter.printHelp(cmdLineSyntax, options);
            return;
        }

        if (line.hasOption(cmdVersion)) {
            System.out.println(Imager.version);
            return;
        }

        Imager imager = new Imager(configurationPath);
        imager.waitForAllThreads();
        imager.restartAndExit();

    } catch (IllegalArgumentException | ParseException | IOException | InstantiationException
            | InterruptedException e) {
        LOGGER.error("Critical exception.", e);
        System.exit(-1);
    }
}

From source file:com.aerospike.example.cache.AsACache.java

public static void main(String[] args) throws AerospikeException {
    try {//from w  ww  .  ja  v  a  2s  .  c o  m
        Options options = new Options();
        options.addOption("h", "host", true, "Server hostname (default: 127.0.0.1)");
        options.addOption("p", "port", true, "Server port (default: 3000)");
        options.addOption("n", "namespace", true, "Namespace (default: test)");
        options.addOption("s", "set", true, "Set (default: demo)");
        options.addOption("u", "usage", false, "Print usage.");

        CommandLineParser parser = new PosixParser();
        CommandLine cl = parser.parse(options, args, false);

        String host = cl.getOptionValue("h", "127.0.0.1");
        String portString = cl.getOptionValue("p", "3000");
        int port = Integer.parseInt(portString);
        String namespace = cl.getOptionValue("n", "test");
        String set = cl.getOptionValue("s", "demo");
        log.debug("Host: " + host);
        log.debug("Port: " + port);
        log.debug("Namespace: " + namespace);
        log.debug("Set: " + set);

        @SuppressWarnings("unchecked")
        List<String> cmds = cl.getArgList();
        if (cmds.size() == 0 && cl.hasOption("u")) {
            logUsage(options);
            return;
        }

        AsACache as = new AsACache(host, port, namespace, set);

        as.work();

    } catch (Exception e) {
        log.error("Critical error", e);
    }
}

From source file:com.thoughtworks.xstream.benchmark.cache.CacheBenchmark.java

public static void main(String[] args) {
    int counter = 10000;
    Product product = null;//from  ww w  . ja  v  a  2s . c o m

    Options options = new Options();
    options.addOption("p", "product", true, "Class name of the product to use for benchmark");
    options.addOption("n", true, "Number of repetitions");

    Parser parser = new PosixParser();
    try {
        CommandLine commandLine = parser.parse(options, args);
        if (commandLine.hasOption('p')) {
            product = (Product) Class.forName(commandLine.getOptionValue('p')).newInstance();
        }
        if (commandLine.hasOption('n')) {
            counter = Integer.parseInt(commandLine.getOptionValue('n'));
        }
    } catch (ParseException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    Harness harness = new Harness();
    // harness.addMetric(new SerializationSpeedMetric(1) {
    // public String toString() {
    // return "Initial run serialization";
    // }
    // });
    // harness.addMetric(new DeserializationSpeedMetric(1, false) {
    // public String toString() {
    // return "Initial run deserialization";
    // }
    // });
    harness.addMetric(new SerializationSpeedMetric(counter));
    harness.addMetric(new DeserializationSpeedMetric(counter, false));
    if (product == null) {
        harness.addProduct(new NoCache());
        harness.addProduct(new Cache122());
        harness.addProduct(new RealClassCache());
        harness.addProduct(new SerializedClassCache());
        harness.addProduct(new AliasedAttributeCache());
        harness.addProduct(new DefaultImplementationCache());
        harness.addProduct(new NoCache());
    } else {
        harness.addProduct(product);
    }
    harness.addTarget(new BasicTarget());
    harness.addTarget(new ExtendedTarget());
    harness.addTarget(new ReflectionTarget());
    harness.addTarget(new SerializableTarget());
    harness.run(new TextReporter(new PrintWriter(System.out, true)));
    System.out.println("Done.");
}

From source file:com.haulmont.mp2xls.MessagePropertiesProcessor.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption(READ_OPT, "read", false, "read messages from project and save to XLS");
    options.addOption(WRITE_OPT, "write", false, "load messages from XLS and write to project");
    options.addOption(OVERWRITE_OPT, "overwrite", false,
            "overwrite existing messages by changed messages from XLS file");
    options.addOption(PROJECT_DIR_OPT, "projectDir", true, "project root directory");
    options.addOption(XLS_FILE_OPT, "xlsFile", true, "XLS file with translations");
    options.addOption(LOG_FILE_OPT, "logFile", true, "log file");
    options.addOption(LANGUAGES_OPT, "languages", true,
            "list of locales separated by comma, for example: 'de,fr'");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;//from w  w  w .  jav  a  2s .  com
    try {
        cmd = parser.parse(options, args);
        if ((!cmd.hasOption(READ_OPT) && !cmd.hasOption(WRITE_OPT)) || !cmd.hasOption(PROJECT_DIR_OPT)
                || !cmd.hasOption(XLS_FILE_OPT) || !cmd.hasOption(LANGUAGES_OPT)) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Messages To/From XLS Convertor", options);
            System.exit(-1);
        }
        if (cmd.hasOption(READ_OPT) && cmd.hasOption(WRITE_OPT)) {
            System.out.println("Please provide either 'read' or 'write' option");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Messages To/From XLS Convertor", options);
            System.exit(-1);
        }

        Set<String> languages = getLanguages(cmd.getOptionValue(LANGUAGES_OPT));

        if (cmd.hasOption(READ_OPT)) {
            LocalizationsBatch localizationsBatch = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT));
            localizationsBatch.setScanLocalizationIds(languages);

            LocalizationBatchExcelWriter.exportToXls(localizationsBatch, cmd.getOptionValue(XLS_FILE_OPT));

        } else if (cmd.hasOption(WRITE_OPT)) {
            LocalizationsBatch sourceLocalization = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT));
            sourceLocalization.setScanLocalizationIds(languages);

            LocalizationsBatch fileLocalization = new LocalizationsBatch(cmd.getOptionValue(XLS_FILE_OPT),
                    cmd.getOptionValue(PROJECT_DIR_OPT));
            fileLocalization.setScanLocalizationIds(languages);

            LocalizationBatchFileWriter fileWriter = new LocalizationBatchFileWriter(sourceLocalization,
                    fileLocalization);
            String logFile = StringUtils.isNotEmpty(cmd.getOptionValue(LOG_FILE_OPT))
                    ? cmd.getOptionValue(LOG_FILE_OPT)
                    : "log.xls";
            fileWriter.process(logFile, cmd.hasOption(OVERWRITE_OPT));
        }
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:com.twitter.hraven.rest.RestServer.java

public static void main(String[] args) throws Exception {
    // parse commandline options
    Options opts = new Options();
    opts.addOption("p", "port", true, "Port for server to bind to (default 8080)");
    opts.addOption("a", "address", true, "IP address for server to bind to (default 0.0.0.0)");
    CommandLine cmd = null;/*from  w  w w.ja  v a2 s . c o m*/
    try {
        cmd = new PosixParser().parse(opts, args);
    } catch (ParseException pe) {
        LOG.fatal("Failed to parse arguments", pe);
        printUsage(opts);
        System.exit(1);
    }

    String address = DEFAULT_ADDRESS;
    int port = DEFAULT_PORT;
    if (cmd.hasOption("p")) {
        try {
            port = Integer.parseInt(cmd.getOptionValue("p"));
        } catch (NumberFormatException nfe) {
            LOG.fatal("Invalid integer '" + cmd.getOptionValue("p") + "'", nfe);
            printUsage(opts);
            System.exit(2);
        }
    }
    if (cmd.hasOption("a")) {
        address = cmd.getOptionValue("a");
    }
    RestServer server = new RestServer(address, port);
    server.startUp();
    // run until we're done
}

From source file:com.github.brosander.java.performance.sampler.analysis.PerformanceSampleAnalyzer.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("i", FILE_OPT, true, "The file to analyze.");
    options.addOption("o", OUTPUT_FILE_OPT, true, "The output file (default json to stdout).");
    options.addOption("p", RELEVANT_PATTERN_OPT, true,
            "Pattern(s) to include as roots in the output (default: " + DEFAULT_PATTERN + ")");
    CommandLineParser parser = new DefaultParser();
    try {/* w  w w  .  j  av a2  s .  c o m*/
        CommandLine commandLine = parser.parse(options, args);
        String file = commandLine.getOptionValue(FILE_OPT);
        if (StringUtils.isEmpty(file)) {
            printUsageAndExit("Must specify file", options, 1);
        }
        Pattern relevantPattern = Pattern
                .compile(commandLine.getOptionValue(RELEVANT_PATTERN_OPT, DEFAULT_PATTERN));
        PerformanceSampleElement performanceSampleElement = relevantElements(relevantPattern,
                new ObjectMapper().readValue(new File(file), PerformanceSampleElement.class));
        updateCounts(performanceSampleElement);
        String outputFile = commandLine.getOptionValue(OUTPUT_FILE_OPT);
        if (StringUtils.isEmpty(outputFile)) {
            new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(System.out,
                    new OutputPerformanceSampleElement(performanceSampleElement));
        } else {
            new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(new File(outputFile),
                    new OutputPerformanceSampleElement(performanceSampleElement));
        }
    } catch (Exception e) {
        e.printStackTrace();
        printUsageAndExit(e.getMessage(), options, 2);
    }
}

From source file:com.artistech.tuio.dispatch.TuioPublish.java

public static void main(String[] args) throws InterruptedException {
    //read off the TUIO port from the command line
    int tuio_port = 3333;
    int zeromq_port = 5565;
    TuioSink.SerializeType serialize_method = TuioSink.SerializeType.PROTOBUF;

    Options options = new Options();
    options.addOption("t", "tuio-port", true, "TUIO Port to listen on. (Default = 3333)");
    options.addOption("z", "zeromq-port", true, "ZeroMQ Port to publish on. (Default = 5565)");
    options.addOption("s", "serialize-method", true,
            "Serialization Method (JSON, OBJECT, Default = PROTOBUF).");
    options.addOption("h", "help", false, "Show this message.");
    HelpFormatter formatter = new HelpFormatter();

    try {/*  ww  w. ja  v  a 2 s.  co  m*/
        CommandLineParser parser = new org.apache.commons.cli.BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {
            formatter.printHelp("tuio-zeromq-publish", options);
            return;
        } else {
            if (cmd.hasOption("t") || cmd.hasOption("tuio-port")) {
                tuio_port = Integer.parseInt(cmd.getOptionValue("t"));
            }
            if (cmd.hasOption("z") || cmd.hasOption("zeromq-port")) {
                zeromq_port = Integer.parseInt(cmd.getOptionValue("z"));
            }
            if (cmd.hasOption("s") || cmd.hasOption("serialize-method")) {
                serialize_method = (TuioSink.SerializeType) Enum.valueOf(TuioSink.SerializeType.class,
                        cmd.getOptionValue("s"));
            }
        }
    } catch (ParseException | IllegalArgumentException ex) {
        System.err.println("Error Processing Command Options:");
        formatter.printHelp("tuio-zeromq-publish", options);
        return;
    }

    //start up the zmq publisher
    ZMQ.Context context = ZMQ.context(1);
    // We send updates via this socket
    try (ZMQ.Socket publisher = context.socket(ZMQ.PUB)) {
        // We send updates via this socket
        publisher.bind("tcp://*:" + Integer.toString(zeromq_port));

        //create a new TUIO sink connected at the specified port
        TuioSink sink = new TuioSink();
        sink.setSerializationType(serialize_method);
        TuioClient client = new TuioClient(tuio_port);

        System.out.println(
                MessageFormat.format("Listening to TUIO message at port: {0}", Integer.toString(tuio_port)));
        System.out.println(
                MessageFormat.format("Publishing to ZeroMQ at port: {0}", Integer.toString(zeromq_port)));
        System.out.println(MessageFormat.format("Serializing as: {0}", serialize_method));
        client.addTuioListener(sink);
        client.connect();

        //while not halted (infinite loop...)
        //read any available messages and publish
        while (!sink.mailbox.isHalted()) {
            ImmutablePair<String, byte[]> msg = sink.mailbox.getMessage();
            publisher.sendMore(msg.left + "." + serialize_method.toString());
            publisher.send(msg.right, 0);
        }

        //cleanup
    }
    context.term();
}

From source file:com.ingby.socbox.bischeck.migration.Properties2ServerProperties.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new GnuParser();
    CommandLine line = null;/*from w  w w  . j  a v  a  2 s .  com*/
    // create the Options
    Options options = new Options();
    options.addOption("u", "usage", false, "show usage.");
    options.addOption("v", "verbose", false, "verbose - do not write to files");
    options.addOption("s", "source", true, "directory old properties.xml is located");
    options.addOption("d", "destination", true, "directory where the new xml files while be stored");

    try {
        // parse the command line arguments
        line = parser.parse(options, args);

    } catch (org.apache.commons.cli.ParseException e) {
        System.out.println("Command parse error:" + e.getMessage());
        Util.ShellExit(1);
    }

    if (line.hasOption("usage")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("DB2XMLConvert", options);
        Util.ShellExit(0);
    }

    Properties2ServerProperties converter = new Properties2ServerProperties();

    if (line.hasOption("source")) {
        String sourcedir = line.getOptionValue("source");
        String destdir = ".";
        if (line.hasOption("destination")) {
            destdir = line.getOptionValue("destination");
        }

        converter.createXMLServerProperties(sourcedir, destdir);

    }
}