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:azkaban.crypto.EncryptionCLI.java

/**
 * Outputs ciphered text to STDOUT.//ww w.j  a v  a2 s  .  co  m
 *
 * usage: EncryptionCLI [-h] -k <pass phrase> -p <plainText> -v <crypto version>
 * -h,--help                       print this message
 * -k,--key <pass phrase>          Passphrase used for encrypting plain text
 * -p,--plaintext <plainText>      Plaintext that needs to be encrypted
 * -v,--version <crypto version>   Version it will use to encrypt Version: [1.0, 1.1]
 *
 * @param args
 * @throws ParseException
 */
public static void main(String[] args) throws ParseException {
    CommandLineParser parser = new DefaultParser();

    if (parser.parse(createHelpOptions(), args, true).hasOption(HELP_KEY)) {
        new HelpFormatter().printHelp(EncryptionCLI.class.getSimpleName(), createOptions(), true);
        return;
    }

    CommandLine line = parser.parse(createOptions(), args);

    String passphraseKey = line.getOptionValue(PASSPHRASE_KEY);
    String plainText = line.getOptionValue(PLAINTEXT_KEY);
    String version = line.getOptionValue(VERSION_KEY);

    ICrypto crypto = new Crypto();
    String cipheredText = crypto.encrypt(plainText, passphraseKey, Version.fromVerString(version));
    System.out.println(cipheredText);
}

From source file:com.aerospike.client.rest.AerospikeRESTfulService.java

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

    Options options = new Options();
    options.addOption("h", "host", true, "Server hostname (default: localhost)");
    options.addOption("p", "port", true, "Server port (default: 3000)");

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

    // set properties
    Properties as = System.getProperties();
    String host = cl.getOptionValue("h", "localhost");
    as.put("seedHost", host);
    String portString = cl.getOptionValue("p", "3000");
    as.put("port", portString);

    // start app/*ww w  .  j a  va 2 s.  co m*/
    SpringApplication.run(AerospikeRESTfulService.class, args);

}

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

public static void main(String[] args) throws AerospikeException {
    try {//from w w w .  j  a va 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.");

        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.aerospike.utility.SetDelete.java

public static void main(String[] args) throws ParseException {
    Options options = new Options();
    options.addOption("h", "host", true, "Server hostname (default: localhost)");
    options.addOption("p", "port", true, "Server port (default: 3000)");
    options.addOption("n", "namespace", true, "Namespace (default: test)");
    options.addOption("s", "set", true, "Set to delete (default: test)");
    options.addOption("u", "usage", false, "Print usage.");

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

    if (args.length == 0 || cl.hasOption("u")) {
        logUsage(options);//  www . j a  va2  s  .  co m
        return;
    }

    String host = cl.getOptionValue("h", "127.0.0.1");
    String portString = cl.getOptionValue("p", "3000");
    int port = Integer.parseInt(portString);
    String set = cl.getOptionValue("s", "test");
    String namespace = cl.getOptionValue("n", "test");

    log.info("Host: " + host);
    log.info("Port: " + port);
    log.info("Name space: " + namespace);
    log.info("Set: " + set);
    if (set == null) {
        log.error("You must specify a set");
        return;
    }
    try {
        final AerospikeClient client = new AerospikeClient(host, port);

        ScanPolicy scanPolicy = new ScanPolicy();
        scanPolicy.includeBinData = false;
        scanPolicy.concurrentNodes = true;
        scanPolicy.priority = Priority.HIGH;
        /*
         * scan the entire Set using scannAll(). This will scan each node 
         * in the cluster and return the record Digest to the call back object
         */
        client.scanAll(scanPolicy, namespace, set, new ScanCallback() {

            public void scanCallback(Key key, Record record) throws AerospikeException {
                /*
                 * for each Digest returned, delete it using delete()
                 */
                if (client.delete(null, key))
                    count++;
                /*
                 * after 25,000 records delete, return print the count.
                 */
                if (count % 25000 == 0) {
                    log.info("Deleted " + count);
                }
            }
        }, new String[] {});
        log.info("Deleted " + count + " records from set " + set);
    } catch (AerospikeException e) {
        int resultCode = e.getResultCode();
        log.info(ResultCode.getResultString(resultCode));
        log.debug("Error details: ", e);
    }
}

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

public static void main(String[] args) throws AerospikeException {
    try {/*from  w w w  .  j  av  a2 s  .  c o m*/
        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.j av  a 2s  .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;
        }

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

        as.work();

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

From source file:it.iit.genomics.cru.genomics.misc.apps.Vcf2tabApp.java

public static void main(String[] args) throws IOException, ParseException {

    Options options = new Options();

    Option helpOpt = new Option("help", "print this message.");
    options.addOption(helpOpt);/*w w  w  .  j a v a2 s . co m*/

    Option option1 = new Option("f", "filename", true, "VCF file to load");
    option1.setRequired(true);
    options.addOption(option1);

    option1 = new Option("o", "outputfile", true, "outputfilene");
    option1.setRequired(true);
    options.addOption(option1);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;

    try {
        // parse the command line arguments
        cmd = parser.parse(options, args, true);
    } catch (ParseException exp) {
        displayUsage("vcf2tab", options);
        System.exit(1);
    }
    if (cmd.hasOption("help")) {
        displayUsage("vcf2tab", options);
        System.exit(0);
    }

    String filename = cmd.getOptionValue("f");
    String outputfilename = cmd.getOptionValue("o");

    Vcf2tab loader = new Vcf2tab();

    loader.file2tab(filename, outputfilename); //(args[0]);

}

From source file:edu.cmu.sv.modelinference.runner.Main.java

public static void main(String[] args) {
    Options cmdOpts = createCmdOptions();

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;//w w w .  ja  v  a  2  s  .  com
    try {
        cmd = parser.parse(cmdOpts, args, true);
    } catch (ParseException exp) {
        logger.error(exp.getMessage());
        System.err.println(exp.getMessage());
        Util.printHelpAndExit(Main.class, cmdOpts);
    }

    String inputType = cmd.getOptionValue(INPUT_TYPE_ARG);
    String tool = cmd.getOptionValue(TOOL_TYPE_ARG);
    String logFile = cmd.getOptionValue(LOG_FILE_ARG).replaceFirst("^~", System.getProperty("user.home"));

    LogHandler<?> logHandler = null;
    boolean found = false;
    for (LogHandler<?> lh : logHandlers) {
        if (lh.getHandlerName().equals(tool)) {
            logHandler = lh;
            found = true;
            break;
        }
    }
    if (!found) {
        StringBuilder sb = new StringBuilder();
        Iterator<LogHandler<?>> logIter = logHandlers.iterator();
        while (logIter.hasNext()) {
            sb.append(logIter.next().getHandlerName());
            if (logIter.hasNext())
                sb.append(", ");
        }
        logger.error("Did not find tool for arg " + tool);

        System.err.println("Supported tools: " + Util.getSupportedHandlersString(logHandlers));
        Util.printHelpAndExit(Main.class, cmdOpts);
    }
    logger.info("Using loghandler for logtype: " + logHandler.getHandlerName());

    logHandler.process(logFile, inputType, cmd.getArgs());
}

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

/**
 * Main entry point.//from  w ww.  java  2  s .  c om
 */
public static void main(String[] args) {

    try {
        Options options = new Options();
        options.addOption("h", "host", true, "Server hostname (default: localhost)");
        options.addOption("p", "port", true, "Server port (default: 3000)");
        options.addOption("U", "user", true, "User name");
        options.addOption("P", "password", true, "Password");
        options.addOption("n", "namespace", true, "Namespace (default: test)");
        options.addOption("s", "set", true, "Set name. Use 'empty' for empty set (default: demoset)");
        options.addOption("g", "gui", false, "Invoke GUI to selectively run tests.");
        options.addOption("d", "debug", false, "Run in debug mode.");
        options.addOption("u", "usage", false, "Print usage.");

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

        if (args.length == 0 || cl.hasOption("u")) {
            logUsage(options);
            return;
        }
        Parameters params = parseParameters(cl);
        String[] exampleNames = cl.getArgs();

        if ((exampleNames.length == 0) && (!cl.hasOption("g"))) {
            logUsage(options);
            return;
        }

        // Check for all.
        for (String exampleName : exampleNames) {
            if (exampleName.equalsIgnoreCase("all")) {
                exampleNames = ExampleNames;
                break;
            }
        }

        if (cl.hasOption("d")) {
            Log.setLevel(Level.DEBUG);
        }

        if (cl.hasOption("g")) {
            GuiDisplay.startGui(params);
        } else {
            Console console = new Console();
            runExamples(console, params, exampleNames);
        }
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
        ex.printStackTrace();
    }
}

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

public static void main(String[] args) throws Exception {
    if (args == null || args.length < 1) {
        System.out.println("Invalid parameter");
        usage();/*from   ww w.  j a v a2s. c o  m*/
        return;
    }
    String topologyName = args[0];
    String[] str2 = Arrays.copyOfRange(args, 1, args.length);
    CommandLineParser parser = new GnuParser();
    Options r = buildGeneralOptions(new Options());
    CommandLine commandLine = parser.parse(r, str2, true);

    int workerNum = 0;
    String component = null;
    List<String> workers = null;
    if (commandLine.hasOption("n")) {
        workerNum = Integer.valueOf(commandLine.getOptionValue("n"));
    }
    if (commandLine.hasOption("p")) {
        component = commandLine.getOptionValue("p");
    }
    if (commandLine.hasOption("w")) {
        String w = commandLine.getOptionValue("w");
        if (!StringUtils.isBlank(w)) {
            workers = Lists.newArrayList();
            String[] parts = w.split(",");
            for (String part : parts) {
                if (part.split(":").length == 2) {
                    workers.add(part.trim());
                }
            }
        }
    }
    upgradeTopology(topologyName, component, workers, workerNum);
}