Example usage for org.apache.commons.cli CommandLineParser parse

List of usage examples for org.apache.commons.cli CommandLineParser parse

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLineParser parse.

Prototype

CommandLine parse(Options options, String[] arguments, boolean stopAtNonOption) throws ParseException;

Source Link

Document

Parse the arguments according to the specified options.

Usage

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

public static void main(String[] args) throws AerospikeException {
    try {/*  w ww.j  a v  a2s .c om*/
        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:com.aerospike.examples.ldt.ttl.LdtExpire.java

public static void main(String[] args) throws AerospikeException {
    try {/*from  w w w .  ja v a 2  s  . co 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.");
        options.addOption("d", "data", false, "Generate data.");

        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;
        }

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

        as.registerUDF();

        if (cl.hasOption("d")) {
            as.generateData();
        } else {
            as.expire();
        }

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

From source file:backtype.storm.command.update_topology.java

/**
 * @param args// w  ww .  jav  a 2s .  co m
 */
public static void main(String[] args) {
    if (args == null || args.length < 3) {
        System.out.println("Invalid parameter");
        usage();
        return;
    }
    String topologyName = args[0];
    try {
        String[] str2 = Arrays.copyOfRange(args, 1, args.length);
        CommandLineParser parser = new GnuParser();
        Options r = buildGeneralOptions(new Options());
        CommandLine commandLine = parser.parse(r, str2, true);

        String pathConf = null;
        String pathJar = null;
        if (commandLine.hasOption("conf")) {
            pathConf = (commandLine.getOptionValues("conf"))[0];
        }
        if (commandLine.hasOption("jar")) {
            pathJar = (commandLine.getOptionValues("jar"))[0];
        }
        if (pathConf != null || pathJar != null)
            updateTopology(topologyName, pathJar, pathConf);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.esri.geoevent.test.performance.OrchestratorMain.java

/**
 * Main method - this is used to when running from command line
 *
 * @param args Command Line Arguments/*  www. j  a  v a2s  . c o  m*/
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {
    // TODO: Localize the messages
    // test harness options
    Options testHarnessOptions = new Options();
    testHarnessOptions.addOption(OptionBuilder.withLongOpt("fixtures")
            .withDescription("The fixtures xml file to load and configure the performance test harness.")
            .hasArg().create("f"));
    testHarnessOptions.addOption("h", "help", false, "print the help message");

    // parse the command line
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(testHarnessOptions, args, false);
    } catch (ParseException ignore) {
        printHelp(testHarnessOptions);
        return;
    }

    if (cmd.getOptions().length == 0) {
        OrchestratorUI ui = new OrchestratorUI();
        ui.run(args);
    } else {
        if (cmd.hasOption("h")) {
            printHelp(testHarnessOptions);
            return;
        }

        if (cmd.hasOption("h") || !cmd.hasOption("f")) {
            printHelp(testHarnessOptions);
            return;
        }

        String fixturesFilePath = cmd.getOptionValue("f");
        // validate
        if (!validateFixturesFile(fixturesFilePath)) {
            printHelp(testHarnessOptions);
            return;
        }

        // parse the xml file
        final Fixtures fixtures;
        try {
            fixtures = fromXML(fixturesFilePath);
        } catch (JAXBException error) {
            System.err.println(ImplMessages.getMessage("TEST_HARNESS_EXECUTOR_CONFIG_ERROR", fixturesFilePath));
            error.printStackTrace();
            return;
        }

        // run the test harness
        try {
            OrchestratorRunner executor = new OrchestratorRunner(fixtures);

            executor.start();
        } catch (RunningException error) {
            error.printStackTrace();
        }

    }

}

From source file:com.linkedin.pinot.transport.perf.ScatterGatherPerfServer.java

/**
 * @param args//from ww  w  .  j  a v  a 2  s .  c  o  m
 */
public static void main(String[] args) throws Exception {

    CommandLineParser cliParser = new GnuParser();
    Options cliOptions = buildCommandLineOptions();

    CommandLine cmd = cliParser.parse(cliOptions, args, true);

    if (!cmd.hasOption(RESPONSE_SIZE_OPT_NAME) || !cmd.hasOption(SERVER_PORT_OPT_NAME)) {
        System.err.println("Missing required arguments !!");
        System.err.println(cliOptions);
        throw new RuntimeException("Missing required arguments !!");
    }

    int responseSize = Integer.parseInt(cmd.getOptionValue(RESPONSE_SIZE_OPT_NAME));
    int serverPort = Integer.parseInt(cmd.getOptionValue(SERVER_PORT_OPT_NAME));

    ScatterGatherPerfServer server = new ScatterGatherPerfServer(serverPort, responseSize, 2); // 2ms latency
    server.run();
}

From source file:com.twitter.heron.ckptmgr.CheckpointManager.java

public static void main(String[] args) throws IOException, ParseException, CheckpointManagerException {
    Options options = constructOptions();
    Options helpOptions = constructHelpOptions();
    CommandLineParser parser = new DefaultParser();
    // parse the help options first.
    CommandLine cmd = parser.parse(helpOptions, args, true);

    if (cmd.hasOption("h")) {
        usage(options);//  w ww .  jav  a  2  s. c o  m
        return;
    }

    try {
        // Now parse the required options
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        throw new RuntimeException("Error parsing command line options ", e);
    }

    String topologyName = cmd.getOptionValue("topologyname");
    String topologyId = cmd.getOptionValue("topologyid");
    String ckptmgrId = cmd.getOptionValue("ckptmgrid");
    int port = Integer.parseInt(cmd.getOptionValue("ckptmgrport"));
    String stateConfigFilename = cmd.getOptionValue("ckptmgrconfig");
    String heronInternalConfig = cmd.getOptionValue("heroninternalconfig");
    SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(heronInternalConfig, true).build();
    CheckpointManagerConfig ckptmgrConfig = CheckpointManagerConfig.newBuilder(true)
            .putAll(stateConfigFilename, true).build();

    // Add the SystemConfig into SingletonRegistry
    SingletonRegistry.INSTANCE.registerSingleton(SystemConfig.HERON_SYSTEM_CONFIG, systemConfig);

    // Init the logging setting and redirect the stdout and stderr to logging
    // For now we just set the logging level as INFO; later we may accept an argument to set it.
    Level loggingLevel = Level.INFO;
    String loggingDir = systemConfig.getHeronLoggingDirectory();

    // Log to file and TMaster
    LoggingHelper.loggerInit(loggingLevel, true);
    LoggingHelper.addLoggingHandler(LoggingHelper.getFileHandler(ckptmgrId, loggingDir, true,
            systemConfig.getHeronLoggingMaximumSize(), systemConfig.getHeronLoggingMaximumFiles()));
    LoggingHelper.addLoggingHandler(new ErrorReportLoggingHandler());

    // Start the actual things
    LOG.info(String.format(
            "Starting topology %s with topologyId %s with " + "Checkpoint Manager Id %s, Port: %d.",
            topologyName, topologyId, ckptmgrId, port));

    LOG.info("System Config: " + systemConfig);

    CheckpointManager checkpointManager = new CheckpointManager(topologyName, topologyId, ckptmgrId,
            CHECKPOINT_MANAGER_HOST, port, systemConfig, ckptmgrConfig);
    checkpointManager.startAndLoop();

    LOG.info("Loops terminated. Exiting.");
}

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

public static void main(String[] args) {
    try {/*w w  w.  j  a v  a2s  .  c om*/
        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.");
        options.addOption("l", "load", false, "Load data.");
        options.addOption("q", "query", false, "Aggregate with query.");
        options.addOption("a", "all", false, "Aggregate all using ScanAggregate.");
        options.addOption("S", "scan", false, "Scan all for testing.");

        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);

        TopTen as = new TopTen(host, port, namespace, set);
        /*
         * Create index for query
         * Index creation only needs to be done once and can be done using AQL or ASCLI also
         */
        IndexTask it = as.client.createIndex(null, as.namespace, as.set, "top-10", TIME_BIN, IndexType.NUMERIC);
        it.waitTillComplete();
        /*
         * Register UDF module
         * Registration only needs to be done after a change in the UDF module.
         */
        RegisterTask rt = as.client.register(null, "udf/leaderboard.lua", "leaderboard.lua", Language.LUA);
        rt.waitTillComplete();

        if (cl.hasOption("l")) {
            as.populateData();
            return;
        } else if (cl.hasOption("q")) {
            as.queryAggregate();
            return;
        } else if (cl.hasOption("a")) {
            as.scanAggregate();
            return;
        } else if (cl.hasOption("S")) {
            as.scanAll();
            return;
        } else {
            logUsage(options);
        }

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