Example usage for org.apache.commons.cli CommandLine getOptionValue

List of usage examples for org.apache.commons.cli CommandLine getOptionValue

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getOptionValue.

Prototype

public String getOptionValue(char opt, String defaultValue) 

Source Link

Document

Retrieve the argument, if any, of an option.

Usage

From source file:com.aerospike.examples.pk.StorePrimaryKey.java

public static void main(String[] args) throws AerospikeException {
    try {//from www .  ja  v  a 2s  . c  om
        Options options = new Options();
        options.addOption("h", "host", true, "Server hostname (default: 172.28.128.6)");
        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", "172.28.128.6");
        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;
        }

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

        as.work();

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

From source file:com.aerospike.examples.BatchUpdateTTL.java

public static void main(String[] args) throws AerospikeException {
    try {// www  . jav  a2 s . 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;
        }

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

        as.work();

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

From source file:act.installer.reachablesexplorer.WikiWebServicesExporter.java

public static void main(String[] args) throws Exception {
    CLIUtil cliUtil = new CLIUtil(WikiWebServicesExporter.class, HELP_MESSAGE, OPTION_BUILDERS);
    CommandLine cl = cliUtil.parseCommandLine(args);

    String host = cl.getOptionValue(OPTION_INPUT_DB_HOST, DEFAULT_HOST);
    Integer port = Integer.parseInt(cl.getOptionValue(OPTION_INPUT_DB_PORT, DEFAULT_PORT));
    String dbName = cl.getOptionValue(OPTION_INPUT_DB, DEFAULT_DB);
    String collection = cl.getOptionValue(OPTION_INPUT_DB_COLLECTION, DEFAULT_COLLECTION);
    String sequenceCollection = cl.getOptionValue(OPTION_INPUT_SEQUENCE_COLLECTION,
            DEFAULT_SEQUENCES_COLLECTION);

    LOGGER.info("Attempting to connect to DB %s:%d/%s, collection %s", host, port, dbName, collection);
    Loader loader = new Loader(host, port, UNUSED_SOURCE_DB, dbName, collection, sequenceCollection,
            DEFAULT_RENDERING_CACHE);// w  w  w.j  av  a2 s  . c  o  m

    JacksonDBCollection<Reachable, String> reachables = loader.getJacksonReachablesCollection();

    LOGGER.info("Connected to DB, reading reachables");

    List<Long> exportIds = !cl.hasOption(OPTION_EXPORT_SOME) ? Collections.emptyList()
            : Arrays.stream(cl.getOptionValues(OPTION_EXPORT_SOME)).map(Long::valueOf)
                    .collect(Collectors.toList());

    TSVWriter<String, String> tsvWriter = new TSVWriter<>(HEADER);
    tsvWriter.open(new File(cl.getOptionValue(OPTION_OUTPUT_FILE)));
    try {
        DBCursor<Reachable> cursor = exportIds.isEmpty() ? reachables.find()
                : reachables.find(DBQuery.in("_id", exportIds));
        int written = 0;
        while (cursor.hasNext()) {
            final Reachable r = cursor.next();

            Map<String, String> row = new HashMap<String, String>() {
                {
                    put("inchi", r.getInchi());
                    put("inchi_key", r.getInchiKey());
                    put("display_name", r.getPageName());
                    put("image_name", r.getStructureFilename());
                }
            };
            tsvWriter.append(row);
            tsvWriter.flush();
            written++;
        }
        LOGGER.info("Wrote %d reachables to output TSV", written);
    } finally {
        tsvWriter.close();
    }
}

From source file:act.installer.reachablesexplorer.PatentFinder.java

public static void main(String[] args) throws Exception {
    CLIUtil cliUtil = new CLIUtil(Loader.class, HELP_MESSAGE, OPTION_BUILDERS);
    CommandLine cl = cliUtil.parseCommandLine(args);

    String host = cl.getOptionValue(OPTION_DB_HOST, DEFAULT_HOST);
    Integer port = Integer.parseInt(cl.getOptionValue(OPTION_DB_PORT, DEFAULT_PORT.toString()));
    String targetDB = cl.getOptionValue(OPTION_TARGET_DB, DEFAULT_TARGET_DATABASE);
    String collection = cl.getOptionValue(OPTION_TARGET_REACHABLES_COLLECTION, DEFAULT_TARGET_COLLECTION);
    LOGGER.info("Connecting to %s:%d/%s, using collection %s", host, port, targetDB, collection);

    Loader loader = new Loader(host, port, UNUSED_SOURCE_DB, targetDB, collection, UNUSED_SEQUENCES_COLLECTION,
            UNUSED_ASSETS_DIR);/*  w w  w .java2s.c  o m*/

    File indexesTopDir = new File(cl.getOptionValue(OPTION_PATENT_INDEX_DIR, DEFAULT_PATENT_INDEX_LOCATION));
    if (!indexesTopDir.exists() || !indexesTopDir.isDirectory()) {
        cliUtil.failWithMessage("Index top-level directory at %s is not a directory",
                indexesTopDir.getAbsolutePath());
    }

    LOGGER.info("Using index top level dir: %s", indexesTopDir.getAbsolutePath());

    PatentFinder finder = new PatentFinder();
    try (Searcher searcher = Searcher.Factory.getInstance().build(indexesTopDir)) {
        finder.run(loader, searcher);
    }
}

From source file:Pong.java

public static void main(String... args) throws Exception {
    System.setProperty("os.max.pid.bits", "16");

    Options options = new Options();
    options.addOption("i", true, "Input chronicle path");
    options.addOption("n", true, "Number of entries to write");
    options.addOption("w", true, "Number of writer threads");
    options.addOption("r", true, "Number of reader threads");
    options.addOption("x", false, "Delete the output chronicle at startup");

    CommandLine cmd = new DefaultParser().parse(options, args);
    final Path output = Paths.get(cmd.getOptionValue("o", "/tmp/__test/chr"));
    final long maxCount = Long.parseLong(cmd.getOptionValue("n", "10000000"));
    final int writerThreadCount = Integer.parseInt(cmd.getOptionValue("w", "4"));
    final int readerThreadCount = Integer.parseInt(cmd.getOptionValue("r", "4"));
    final boolean deleteOnStartup = cmd.hasOption("x");

    if (deleteOnStartup) {
        FileUtil.removeRecursive(output);
    }/* w  ww  . jav  a2s . c o  m*/

    final Chronicle chr = ChronicleQueueBuilder.vanilla(output.toFile()).build();

    final ExecutorService executor = Executors.newFixedThreadPool(4);
    final List<Future<?>> futures = new ArrayList<>();

    final long totalCount = writerThreadCount * maxCount;
    final long t0 = System.nanoTime();

    for (int i = 0; i != readerThreadCount; ++i) {
        final int tid = i;
        futures.add(executor.submit((Runnable) () -> {
            try {
                IntLongMap counts = HashIntLongMaps.newMutableMap();
                ExcerptTailer tailer = chr.createTailer();

                final StringBuilder sb1 = new StringBuilder();
                final StringBuilder sb2 = new StringBuilder();

                long count = 0;
                while (count != totalCount) {
                    if (!tailer.nextIndex())
                        continue;
                    final int id = tailer.readInt();
                    final long val = tailer.readStopBit();
                    final long longValue = tailer.readLong();
                    sb1.setLength(0);
                    sb2.setLength(0);
                    tailer.read8bitText(sb1);
                    tailer.read8bitText(sb2);
                    if (counts.addValue(id, 1) - 1 != val || longValue != 0x0badcafedeadbeefL
                            || !StringInterner.isEqual("FooBar", sb1)
                            || !StringInterner.isEqual("AnotherFooBar", sb2)) {
                        System.out.println("Unexpected value " + id + ", " + val + ", "
                                + Long.toHexString(longValue) + ", " + sb1.toString() + ", " + sb2.toString());
                        return;
                    }
                    ++count;
                    if (count % 1_000_000 == 0) {
                        long t1 = System.nanoTime();
                        System.out.println(tid + " " + (t1 - t0) / 1e6 + " ms");
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }));
    }
    for (Future f : futures) {
        f.get();
    }
    executor.shutdownNow();

    final long t1 = System.nanoTime();
    System.out.println("Done. Rough time=" + (t1 - t0) / 1e6 + " ms");
}

From source file:act.installer.bing.BingSearcher.java

public static void main(String args[]) {

    CLIUtil cliUtil = new CLIUtil(BingSearcher.class, HELP_MESSAGE, OPTION_BUILDERS);
    CommandLine cl = cliUtil.parseCommandLine(args);
    MongoDB db = new MongoDB(cl.getOptionValue(OPTION_DB_HOST, DEFAULT_HOST),
            Integer.parseInt(cl.getOptionValue(OPTION_DB_PORT, DEFAULT_PORT)),
            cl.getOptionValue(OPTION_DB_NAME, DEFAULT_DATABASE));
    BingSearcher bingSearcher = new BingSearcher(db, true, cl.hasOption(OPTION_CACHE_ONLY));
    bingSearcher.addBingSearchResultsForEntireDatabase();
}

From source file:com.uber.tchannel.ping.PingServer.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("p", "port", true, "Server Port to connect to");
    options.addOption("?", "help", false, "Usage");
    HelpFormatter formatter = new HelpFormatter();

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("?")) {
        formatter.printHelp("PingClient", options, true);
        return;/*ww w . j  a v a 2s .  co m*/
    }

    int port = Integer.parseInt(cmd.getOptionValue("p", "8888"));

    System.out.println(String.format("Starting server on port: %d", port));
    new PingServer(port).run();
    System.out.println("Stopping server...");
}

From source file:io.rhiot.spec.IoTSpec.java

public static void main(String[] args) throws Exception {

    CommandLineParser parser = new DefaultParser();

    Options options = new Options();
    options.addOption(Option.builder("c").longOpt(CONFIG).desc(
            "Location of the test configuration file. A default value is 'src/main/resources/test.yaml' for easy IDE testing")
            .hasArg().build());// w w w  . j a  va2s.co  m

    options.addOption(Option.builder("i").longOpt(INSTANCE).desc("Instance of the test; A default value is 1")
            .hasArg().build());

    options.addOption(Option.builder("r").longOpt(REPORT)
            .desc("Location of the test report. A default value is 'target/report.csv'").hasArg().build());

    CommandLine line = parser.parse(options, args);
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    TestProfile test = mapper.readValue(new File(line.getOptionValue(CONFIG, "src/main/resources/test.yaml")),
            TestProfile.class);
    int instance = Integer.valueOf(line.getOptionValue(INSTANCE, "1"));
    test.setInstance(instance);
    String report = line.getOptionValue(REPORT, "target/report.csv");
    test.setReport(new CSVReport(report));

    LOG.info("Test '" + test.getName() + "' instance " + instance + " started");
    final List<Driver> drivers = test.getDrivers();
    ExecutorService executorService = Executors.newFixedThreadPool(drivers.size());
    List<Future<Void>> results = executorService.invokeAll(drivers, test.getDuration(), TimeUnit.MILLISECONDS);
    executorService.shutdownNow();
    executorService.awaitTermination(5, TimeUnit.SECONDS);

    results.forEach(result -> {
        try {
            result.get();
        } catch (ExecutionException execution) {
            LOG.warn("Exception running driver", execution);
        } catch (Exception interrupted) {
        }
    });

    drivers.forEach(driver -> {
        driver.stop();

        try {
            test.getReport().print(driver);
        } catch (Exception e) {
            LOG.warn("Failed to write reports for the driver " + driver);
        }
        LOG.debug("Driver " + driver);
        LOG.debug("\t " + driver.getResult());
    });
    test.getReport().close();

    LOG.info("Test '" + test.getName() + "' instance " + instance + " finished");

}

From source file:com.aerospike.examples.travel.FlighAggregation.java

public static void main(String[] args) throws AerospikeException {
    try {// w ww  . jav a2s.  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;
        }

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

        as.init();
        as.work();

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

From source file:di.uniba.it.tee2.wiki.Wikidump2Text.java

/**
 * @param args the command line arguments
 *//*from ww  w.ja  v  a 2  s.  c  om*/
public static void main(String[] args) {
    try {
        CommandLine cmd = cmdParser.parse(options, args);
        if (cmd.hasOption("l") && cmd.hasOption("d") && cmd.hasOption("o")) {
            encoding = cmd.getOptionValue("e", "UTF-8");
            int counter = 0;
            try {
                BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                        new GZIPOutputStream(new FileOutputStream(cmd.getOptionValue("o"))), "UTF-8"));
                WikipediaDumpIterator it = new WikipediaDumpIterator(new File(cmd.getOptionValue("d")),
                        encoding);
                PageCleaner cleaner = PageCleanerWrapper.getInstance(cmd.getOptionValue("l"));
                while (it.hasNext()) {
                    WikiPage wikiPage = it.next();
                    ParsedPage parsedPage = wikiPage.getParsedPage();
                    if (parsedPage != null) {
                        String title = wikiPage.getTitle();
                        if (!title.matches(notValidTitle)) {
                            if (parsedPage.getText() != null) {
                                writer.append(cleaner.clean(parsedPage.getText()));
                                writer.newLine();
                                writer.newLine();
                                counter++;
                                if (counter % 10000 == 0) {
                                    System.out.println(counter);
                                    writer.flush();
                                }
                            }
                        }
                    }
                }
                writer.flush();
                writer.close();
            } catch (Exception ex) {
                Logger.getLogger(Wikidump2Text.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.out.println("Indexed pages: " + counter);
        } else {
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("Wikipedia dump to text", options, true);
        }
    } catch (ParseException ex) {
        Logger.getLogger(Wikidump2Text.class.getName()).log(Level.SEVERE, null, ex);
    }
}