Example usage for org.apache.commons.cli Option Option

List of usage examples for org.apache.commons.cli Option Option

Introduction

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

Prototype

public Option(String opt, String longOpt, boolean hasArg, String description) throws IllegalArgumentException 

Source Link

Document

Creates an Option using the specified parameters.

Usage

From source file:io.minimum.minecraft.rbclean.RedisBungeeClean.java

public static void main(String... args) {
    Options options = new Options();

    Option hostOption = new Option("h", "host", true, "Sets the Redis host to use.");
    hostOption.setRequired(true);/*from   ww w .  j av  a2 s. c o m*/
    options.addOption(hostOption);

    Option portOption = new Option("p", "port", true, "Sets the Redis port to use.");
    options.addOption(portOption);

    Option passwordOption = new Option("w", "password", true, "Sets the Redis password to use.");
    options.addOption(passwordOption);

    Option dryRunOption = new Option("d", "dry-run", false, "Performs a dry run (no data is modified).");
    options.addOption(dryRunOption);

    CommandLine commandLine;

    try {
        commandLine = new DefaultParser().parse(options, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("RedisBungeeClean", options);
        return;
    }

    int port = commandLine.hasOption('p') ? Integer.parseInt(commandLine.getOptionValue('p')) : 6379;

    try (Jedis jedis = new Jedis(commandLine.getOptionValue('h'), port, 0)) {
        if (commandLine.hasOption('w')) {
            jedis.auth(commandLine.getOptionValue('w'));
        }

        System.out.println("Fetching UUID cache...");
        Map<String, String> uuidCache = jedis.hgetAll("uuid-cache");
        Gson gson = new Gson();

        // Just in case we need it, compress everything in JSON format.
        if (!commandLine.hasOption('d')) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
            File file = new File("uuid-cache-previous-" + dateFormat.format(new Date()) + ".json.gz");
            try {
                file.createNewFile();
            } catch (IOException e) {
                System.out.println("Can't write backup of the UUID cache, will NOT proceed.");
                e.printStackTrace();
                return;
            }

            System.out.println("Creating backup (as " + file.getName() + ")...");

            try (OutputStreamWriter bw = new OutputStreamWriter(
                    new GZIPOutputStream(new FileOutputStream(file)))) {
                gson.toJson(uuidCache, bw);
            } catch (IOException e) {
                System.out.println("Can't write backup of the UUID cache, will NOT proceed.");
                e.printStackTrace();
                return;
            }
        }

        System.out.println("Cleaning out the bird cage (this may take a while...)");
        int originalSize = uuidCache.size();
        for (Iterator<Map.Entry<String, String>> it = uuidCache.entrySet().iterator(); it.hasNext();) {
            CachedUUIDEntry entry = gson.fromJson(it.next().getValue(), CachedUUIDEntry.class);

            if (entry.expired()) {
                it.remove();
            }
        }
        int newSize = uuidCache.size();

        if (commandLine.hasOption('d')) {
            System.out.println(
                    (originalSize - newSize) + " records would be expunged if a dry run was not conducted.");
        } else {
            System.out.println("Expunging " + (originalSize - newSize) + " records...");
            Transaction transaction = jedis.multi();
            transaction.del("uuid-cache");
            transaction.hmset("uuid-cache", uuidCache);
            transaction.exec();
            System.out.println("Expunging complete.");
        }
    }
}

From source file:com.basingwerk.utilisation.Utilisation.java

public static void main(final String[] args) {
    String dataFile = null;//from ww  w  .  ja  v a 2  s . c  o m

    Options options = new Options();

    Option helpOption = new Option("h", "help", false, "print this help");
    Option serverURLOption = new Option("l", "logfile", true, "log file");

    options.addOption(helpOption);
    options.addOption(serverURLOption);

    CommandLineParser argsParser = new PosixParser();

    try {
        CommandLine commandLine = argsParser.parse(options, args);

        if (commandLine.hasOption(helpOption.getOpt())) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

        dataFile = commandLine.getOptionValue(serverURLOption.getOpt());
        String[] otherArgs = commandLine.getArgs();

        if (dataFile == null || otherArgs.length > 1) {
            System.out.println("Please specify a logfile");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage grapher", options);
            System.exit(0);
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
    }

    final UsagePlotter demo = new UsagePlotter("Usage", new File(dataFile));
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
}

From source file:io.proscript.jlight.JLight.java

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

    CommandLineParser parser = new DefaultParser();
    Options options = new Options();

    Option host = new Option("h", "host", true, "Host of the HTTP server (default 127.0.0.1)");
    Option port = new Option("p", "port", true, "Port of the HTTP server (default 9000)");

    Option main = new Option("c", "class", true, "Application to run, e.g. org.vendor.class");
    Option help = new Option("h", "help", false, "Display help and exit");
    Option version = new Option("v", "version", false, "Display JLight version");

    options.addOption(host);/* w ww.j  a v a 2  s.  c om*/
    options.addOption(port);

    options.addOption(main);
    options.addOption(help);
    options.addOption(version);

    CommandLine line;

    try {
        line = parser.parse(options, args);

        if (line.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            Version.print();
            formatter.printHelp("jlight", options);
            return;
        }

        if (line.hasOption("v")) {
            Version.print();
            return;
        }

        if (!line.hasOption("c")) {
            throw new ParseException("Option 'class' is required");
        }

        Runtime.run(line);
    } catch (ParseException exp) {
        System.err.println(exp.getMessage());
    }
}

From source file:com.github.braully.graph.UtilResult.java

public static void main(String... args) throws Exception {
    Options options = new Options();

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(false);//from  w w w.ja  v a 2  s  .  c  om
    options.addOption(input);

    Option verb = new Option("v", "verbose", false, "verbose process");
    input.setRequired(false);
    options.addOption(verb);

    Option output = new Option("o", "output", true, "output file");
    output.setRequired(false);
    options.addOption(output);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("UtilResult", options);

        System.exit(1);
        return;
    }

    String inputFilePath = cmd.getOptionValue("input");
    if (inputFilePath == null) {
        inputFilePath = "/home/strike/grafos-para-processar/mft2/resultado.txt";
    }
    if (inputFilePath != null) {
        if (inputFilePath.toLowerCase().endsWith(".txt")) {
            processFileTxt(inputFilePath);
        } else if (inputFilePath.toLowerCase().endsWith(".json")) {
            processFileJson(inputFilePath);
        }
    }
}

From source file:com.evolveum.midpoint.tools.gui.Main.java

public static void main(String[] args) throws Exception {
    Options options = new Options();

    Option propertiesLocaleDelimiter = new Option("d", "delimiter", true,
            "Delimiter for locale name in properties file. Default is '_' (underscore).");
    options.addOption(propertiesLocaleDelimiter);
    Option targetFolder = new Option("t", "targetFolder", true,
            "Target folder where properties file is generated.");
    targetFolder.setRequired(true);//from  ww w. jav a  2 s .com
    options.addOption(targetFolder);
    Option baseFolder = new Option("b", "baseFolder", true, "Base folder used for properties files searching.");
    baseFolder.setRequired(true);
    options.addOption(baseFolder);
    Option localesToCheck = new Option("l", "locale", true, "Locales to check.");
    localesToCheck.setRequired(true);
    options.addOption(localesToCheck);
    Option recursiveFolderToCheck = new Option("r", "folderRecursive", true,
            "Folder used for recursive search for properties files.");
    options.addOption(recursiveFolderToCheck);
    Option nonRecursiveFolderToCheck = new Option("n", "folderNonRecursive", true,
            "Folder used for non recursive search for properties files.");
    options.addOption(nonRecursiveFolderToCheck);
    Option help = new Option("h", "help", false, "Print this help.");
    options.addOption(help);
    Option disableBackup = new Option("db", "disableBackup", false, "Disable backuping property files.");
    options.addOption(disableBackup);

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine line = parser.parse(options, args);
        if (line.hasOption(help.getOpt())) {
            printHelp(options);
            return;
        }

        if (!line.hasOption(recursiveFolderToCheck.getOpt())
                && !line.hasOption(nonRecursiveFolderToCheck.getOpt())) {
            printHelp(options);
            return;
        }

        GeneratorConfiguration config = new GeneratorConfiguration();
        if (line.hasOption(baseFolder.getOpt())) {
            config.setBaseFolder(new File(line.getOptionValue(baseFolder.getOpt())));
        }
        if (line.hasOption(targetFolder.getOpt())) {
            config.setTargetFolder(new File(line.getOptionValue(targetFolder.getOpt())));
        }
        if (line.hasOption(propertiesLocaleDelimiter.getOpt())) {
            config.setPropertiesLocaleDelimiter(line.getOptionValue(propertiesLocaleDelimiter.getOpt()));
        }
        if (line.hasOption(recursiveFolderToCheck.getOpt())) {
            String[] recursives = line.getOptionValues(recursiveFolderToCheck.getOpt());
            if (recursives != null && recursives.length > 0) {
                for (String recursive : recursives) {
                    config.getRecursiveFolderToCheck().add(recursive);
                }
            }
        }
        if (line.hasOption(nonRecursiveFolderToCheck.getOpt())) {
            String[] nonRecursives = line.getOptionValues(nonRecursiveFolderToCheck.getOpt());
            if (nonRecursives != null && nonRecursives.length > 0) {
                for (String nonRecursive : nonRecursives) {
                    config.getNonRecursiveFolderToCheck().add(nonRecursive);
                }
            }
        }

        if (line.hasOption(localesToCheck.getOpt())) {
            String[] locales = line.getOptionValues(localesToCheck.getOpt());
            for (String locale : locales) {
                config.getLocalesToCheck().add(getLocaleFromString(locale));
            }
        }

        if (line.hasOption(disableBackup.getOpt())) {
            config.setDisableBackup(true);
        }

        PropertiesGenerator generator = new PropertiesGenerator(config);
        generator.generate();
    } catch (ParseException ex) {
        System.out.println("Error: " + ex.getMessage());
        printHelp(options);
    } catch (Exception ex) {
        System.out.println("Something is broken.");
        ex.printStackTrace();
    }
}

From source file:com.github.braully.graph.UtilResultCompare.java

public static void main(String... args) throws Exception {
    Options options = new Options();

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(false);/*w  ww  .  j av a2  s .c  om*/
    options.addOption(input);

    Option output = new Option("o", "output", true, "output file");
    output.setRequired(false);
    options.addOption(output);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("UtilResult", options);

        System.exit(1);
        return;
    }

    String inputFilePath = cmd.getOptionValue("input");
    if (inputFilePath == null) {
        inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-quartic-ht.txt";

        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-mft-parcial-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-highlyirregular-ht.txt";
        //            inputFilePath = "/home/strike/Documentos/grafos-processados/mtf/resultado-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-hypo-parcial-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-eul-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-almhypo-ht.txt";
        //            inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-Almost_hypohamiltonian_graphs_cubic-parcial-ht.txt";
    }
    if (inputFilePath != null) {
        if (inputFilePath.toLowerCase().endsWith(".txt")) {
            processFileTxt(inputFilePath);
        } else if (inputFilePath.toLowerCase().endsWith(".json")) {
            processFileJson(inputFilePath);
        }
    }
}

From source file:eu.edisonproject.utility.execute.Main.java

public static void main(String args[]) {
    Options options = new Options();
    Option operation = new Option("op", "operation", true,
            "type of operation to perform. " + "To move cached terms from org.mapdb.DB 'm'");
    operation.setRequired(true);/*from ww  w  .j  a  v  a 2 s.co  m*/
    options.addOption(operation);

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(true);
    options.addOption(input);

    String helpmasg = "Usage: \n";
    for (Object obj : options.getOptions()) {
        Option op = (Option) obj;
        helpmasg += op.getOpt() + ", " + op.getLongOpt() + "\t Required: " + op.isRequired() + "\t\t"
                + op.getDescription() + "\n";
    }

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        switch (cmd.getOptionValue("operation")) {
        case "m":
            DBTools.portTermCache2Hbase(cmd.getOptionValue("input"));
            DBTools.portBabelNetCache2Hbase(cmd.getOptionValue("input"));
            break;
        default:
            System.out.println(helpmasg);
        }

    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, helpmasg, ex);
    }
}

From source file:main.Main.java

/**
 * The public main function./*  www.  java 2  s .c  o  m*/
 * @param args
 */
public static void main(String[] args) {
    System.out.println("Starting");

    Options options = new Options();

    Option solutionOption = new Option("s", "solution", true,
            "This will be the " + "solution of the cross word game. (aka. This will be the first"
                    + " vertical word on the canvas.)");

    //        solutionOption.setRequired(true);

    Option numOfBatchOption = new Option("n", "numOfBatch", true, "");

    Option verboseOption = new Option("v", "verbose", false, "Print some debug information during running.");
    Option veryVerboseOption = new Option("vv", "very-verbose", false, "Print more debug information.");

    options.addOption(solutionOption);
    options.addOption(numOfBatchOption);
    options.addOption(verboseOption);
    options.addOption(veryVerboseOption);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("utility-name", options);

        System.exit(1);
        return;
    }

    System.out.println(cmd.getArgList());

    int debugLevel = 0;
    if (cmd.hasOption("verbose")) {
        debugLevel = 1;
    }
    if (cmd.hasOption("very-verbose")) {
        debugLevel = 2;
    }
    String solution = cmd.getOptionValue("solution");
    if (null == solution) {
        startGui();
    } else {
        int numOfBatch = Integer.valueOf(cmd.getOptionValue("numOfBatch", "200"));
        System.out.println(solution);
        Generator gen = new Generator(solution, debugLevel); // <---- EDIT THIS LINE FOR DIFFERENT SOLUTIONS.
        long startTime = System.currentTimeMillis();
        gen.generate(numOfBatch);
        long estimatedTime = System.currentTimeMillis() - startTime;
        System.out.print("estimatedTime: " + estimatedTime + "ms");
    }
}

From source file:edu.mit.csail.sdg.alloy4.VizGUI.java

/**
 * @param args/*from   ww  w  . j  ava2 s  .  c o  m*/
 */
public static void main(String[] args) {
    // create the command line parser
    CommandLineParser parser = new PosixParser();

    // create the Options
    Options optionsArg = new Options();
    Option helpOpt = new Option("?", "help", false, "print this message");
    Option inputFileOpt = new Option("f", "file", true, "the name of the xml file to show");
    inputFileOpt.setRequired(true);

    optionsArg.addOption(helpOpt);
    optionsArg.addOption(inputFileOpt);

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

        if (line.hasOption(helpOpt.getOpt())) {
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("vizgui", optionsArg);
            return;
        }

    } catch (ParseException exp) {
        System.err.println("Unexpected exception:" + exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("vizgui", optionsArg);
        return;
    }

    String inputFile = null;
    if (line.hasOption(inputFileOpt.getOpt())) {
        inputFile = line.getOptionValue(inputFileOpt.getOpt());
        if (inputFile == null) {
            System.err.println("Invalid input file");
        }
    }

    new edu.mit.csail.sdg.alloy4viz.VizGUI(true, inputFile, null);

}

From source file:com.rabbitmq.examples.FileProducer.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption(new Option("h", "uri", true, "AMQP URI"));
    options.addOption(new Option("p", "port", true, "broker port"));
    options.addOption(new Option("t", "type", true, "exchange type"));
    options.addOption(new Option("e", "exchange", true, "exchange name"));
    options.addOption(new Option("k", "routing-key", true, "routing key"));

    CommandLineParser parser = new GnuParser();

    try {/* w w  w.  ja va 2  s . c  o  m*/
        CommandLine cmd = parser.parse(options, args);

        String uri = strArg(cmd, 'h', "amqp://localhost");
        String exchangeType = strArg(cmd, 't', "direct");
        String exchange = strArg(cmd, 'e', null);
        String routingKey = strArg(cmd, 'k', null);

        ConnectionFactory connFactory = new ConnectionFactory();
        connFactory.setUri(uri);
        Connection conn = connFactory.newConnection();

        final Channel ch = conn.createChannel();

        if (exchange == null) {
            System.err.println("Please supply exchange name to send to (-e)");
            System.exit(2);
        }
        if (routingKey == null) {
            System.err.println("Please supply routing key to send to (-k)");
            System.exit(2);
        }
        ch.exchangeDeclare(exchange, exchangeType);

        for (String filename : cmd.getArgs()) {
            System.out.print("Sending " + filename + "...");
            File f = new File(filename);
            FileInputStream i = new FileInputStream(f);
            byte[] body = new byte[(int) f.length()];
            i.read(body);
            i.close();

            Map<String, Object> headers = new HashMap<String, Object>();
            headers.put("filename", filename);
            headers.put("length", (int) f.length());
            BasicProperties props = new BasicProperties.Builder().headers(headers).build();
            ch.basicPublish(exchange, routingKey, props, body);
            System.out.println(" done.");
        }

        conn.close();
    } catch (Exception ex) {
        System.err.println("Main thread caught exception: " + ex);
        ex.printStackTrace();
        System.exit(1);
    }
}