Example usage for org.apache.commons.cli OptionBuilder withLongOpt

List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt

Introduction

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

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:de.tudarmstadt.lt.lm.app.Ngrams.java

@SuppressWarnings("static-access")
public Ngrams(String[] args) {

    Options opts = new Options();
    opts.addOption(OptionBuilder.withLongOpt("help").withDescription("Display help message.").create("?"));
    opts.addOption(OptionBuilder.withLongOpt("ptype").withArgName("class").hasArg().withDescription(
            "specify the instance of the language model provider that you want to use: {LtSegProvider, BreakIteratorStringProvider, UimaStringProvider, PreTokenizedStringProvider} (default: LtSegProvider)")
            .create("p"));
    opts.addOption(OptionBuilder.withLongOpt("cardinality").withArgName("ngram-order").hasArg().withDescription(
            "Specify the cardinality of the ngrams (min. 1). Specify a range using 'from-to'. (Examples: 5 = extract 5grams; 1-5 = extract 1grams, 2grams, ..., 5grams; default: 1-5).")
            .create("n"));
    opts.addOption(OptionBuilder.withLongOpt("file").withArgName("filename").hasArg()
            .withDescription("specify the file to read from. Specify '-' to read from stdin. (default: '-')")
            .create("f"));
    opts.addOption(OptionBuilder.withLongOpt("out").withArgName("name").hasArg()
            .withDescription("Specify the output file. Specify '-' to use stdout. (default: '-').")
            .create("o"));
    opts.addOption(OptionBuilder.withLongOpt("accross_sentences").hasOptionalArg().withArgName("{true|false}")
            .withDescription("Generate Ngrams across sentence boundaries.").create("a"));

    try {/*from   w  ww .  ja  v  a  2  s . c o  m*/
        CommandLine cmd = new ExtendedGnuParser(true).parse(opts, args);
        if (cmd.hasOption("help"))
            CliUtils.print_usage_quit(System.err, Ngrams.class.getSimpleName(), opts, USAGE_HEADER, null, 0);

        _provider_type = cmd.getOptionValue("ptype", LtSegProvider.class.getSimpleName());
        _file = cmd.getOptionValue("file", "-");
        _out = cmd.getOptionValue("out", "-");
        _accross_sentences = cmd.hasOption("accross_sentences");
        String order = cmd.getOptionValue("cardinality", "1-5");
        if (_accross_sentences && cmd.getOptionValue("accross_sentences") != null)
            _accross_sentences = Boolean.parseBoolean(cmd.getOptionValue("accross_sentences"));

        int dash_index = order.indexOf('-');
        _order_to = Integer.parseInt(order.substring(dash_index + 1, order.length()).trim());
        _order_from = _order_to;
        if (dash_index == 0)
            _order_from = 1;
        if (dash_index > 0)
            _order_from = Math.max(1, Integer.parseInt(order.substring(0, dash_index).trim()));

    } catch (Exception e) {
        CliUtils.print_usage_quit(System.err, Ngrams.class.getSimpleName(), opts, USAGE_HEADER,
                String.format("%s: %s%n", e.getClass().getSimpleName(), e.getMessage()), 1);
    }
}

From source file:de.tudarmstadt.lt.lm.app.SentPerp.java

/**
 * //from  w  ww . j a  v  a  2  s  .c om
 */
@SuppressWarnings("static-access")
public SentPerp(String args[]) {
    Options opts = new Options();

    opts.addOption(new Option("?", "help", false, "display this message"));
    opts.addOption(OptionBuilder.withLongOpt("port").withArgName("port-number").hasArg()
            .withDescription(
                    String.format("Specifies the port on which the rmi registry listens (default: %d).",
                            Registry.REGISTRY_PORT))
            .create("p"));
    opts.addOption(OptionBuilder.withLongOpt("selftest")
            .withDescription("Run a selftest, compute perplexity of ngrams in specified LM.").create("s"));
    opts.addOption(OptionBuilder.withLongOpt("quiet").withDescription("Run with minimum outout on stdout.")
            .create("q"));
    opts.addOption(OptionBuilder.withLongOpt("noov").hasOptionalArg().withArgName("{true|false}")
            .withDescription("Do not consider oov terms, i.e. ngrams that end in an oov term. (default: false)")
            .create());
    opts.addOption(OptionBuilder.withLongOpt("oovreflm").withArgName("identifier").hasArg().withDescription(
            "Do not consider oov terms with respect to the provided lm, i.e. ngrams that end in an oov term in the referenced lm. (default use current lm)")
            .create());
    opts.addOption(OptionBuilder.withLongOpt("host").withArgName("hostname").hasArg()
            .withDescription("Specifies the hostname on which the rmi registry listens (default: localhost).")
            .create("h"));
    opts.addOption(OptionBuilder.withLongOpt("file").withArgName("name").hasArg().withDescription(
            "Specify the file or directory that contains '.txt' files that are used as source for testing perplexity with the specified language model. Specify '-' to pipe from stdin. (default: '-').")
            .create("f"));
    opts.addOption(OptionBuilder.withLongOpt("out").withArgName("name").hasArg()
            .withDescription("Specify the output file. Specify '-' to use stdout. (default: '-').")
            .create("o"));
    opts.addOption(OptionBuilder.withLongOpt("name").withArgName("identifier").isRequired().hasArg()
            .withDescription("Specify the name of the language model provider that you want to connect to.")
            .create("i"));

    try {
        CommandLine cmd = new ExtendedGnuParser(true).parse(opts, args);
        if (cmd.hasOption("help"))
            CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, null, 0);

        _host = cmd.getOptionValue("host", "localhost");
        _rmiport = Integer.parseInt(cmd.getOptionValue("port", String.valueOf(Registry.REGISTRY_PORT)));
        _file = cmd.getOptionValue("file", "-");
        _out = cmd.getOptionValue("out", "-");
        _name = cmd.getOptionValue("name");
        _host = cmd.getOptionValue("host", "localhost");
        _selftest = cmd.hasOption("selftest");
        _quiet = cmd.hasOption("quiet");
        _no_oov = cmd.hasOption("noov");
        if (_no_oov && cmd.getOptionValue("noov") != null)
            _no_oov = Boolean.parseBoolean(cmd.getOptionValue("noov"));
        _oovreflm_name = cmd.getOptionValue("oovreflm");

    } catch (Exception e) {
        LOG.error("{}: {}- {}", _rmi_string, e.getClass().getSimpleName(), e.getMessage());
        CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER,
                String.format("%s: %s%n", e.getClass().getSimpleName(), e.getMessage()), 1);
    }
    _rmi_string = String.format("rmi://%s:%d/%s", _host, _rmiport, _name);
}

From source file:br.usp.poli.lta.cereda.macro.util.CLIParser.java

/**
 * Realiza a anlise dos argumentos de linha de comando e retorna um par
 * contendo o texto a ser expandido e o arquivo de sada.
 * @return Um par contendo o texto a ser expandido e o arquivo de sada.
 * @throws IOException Um dos arquivos de entrada no existe.
 *///from  ww  w .jav a  2 s  . c o m
public Pair<String, File> parse() throws IOException {

    // opo de entrada
    Option input = OptionBuilder.withLongOpt("input").hasArgs().withArgName("lista de arquivos")
            .withDescription("arquivos de entrada").create("i");

    // opo de sada
    Option output = OptionBuilder.withLongOpt("output").hasArg().withArgName("arquivo")
            .withDescription("arquivo de sada").create("o");

    // opo do editor embutido
    Option ui = OptionBuilder.withLongOpt("editor").withDescription("editor grfico").create("e");

    Options options = new Options();
    options.addOption(input);
    options.addOption(output);
    options.addOption(ui);

    try {

        // parsing dos argumentos
        Parser parser = new BasicParser();
        CommandLine line = parser.parse(options, arguments);

        // verifica se  uma chamada ao editor e retorna em caso positivo
        if (line.hasOption("e")) {
            editor = true;
            return null;
        }

        // se no  uma chamada ao editor de macros,  necessrio verificar
        // se existe um arquivo de entrada
        if (!line.hasOption("i")) {
            throw new ParseException("");
        }

        // existem argumentos restantes, o que representa situao de erro
        if (!line.getArgList().isEmpty()) {
            throw new ParseException("");
        }

        String text = "";
        File out = line.hasOption("output") ? new File(line.getOptionValue("output")) : null;

        if (out == null) {
            logger.info("A sada ser gerada no terminal.");
        } else {
            logger.info("A sada ser gerada no arquivo '{}'.", out.getName());
        }

        // faz a leitura de todos os arquivos e concatena seu contedo em
        // uma varivel
        logger.info("Iniciando a leitura dos arquivos de entrada.");
        String[] files = line.getOptionValues("input");
        for (String file : files) {
            logger.info("Lendo arquivo '{}'.", file);
            text = text.concat(FileUtils.readFileToString(new File(file), Charset.forName("UTF-8")));
        }

        // retorna o par da varivel contendo o texto de todos os arquivos
        // e a referncia ao arquivo de sada (podendo este ser nulo)
        return new Pair<>(text, out);

    } catch (ParseException exception) {

        // imprime a ajuda
        HelpFormatter help = new HelpFormatter();
        help.printHelp("expander ( --editor | --input <lista de arquivos>" + " [ --output <arquivo> ] )",
                options);
    }

    // retorna um valor invlido indicando para no prosseguir com o
    // processo de expanso
    return null;

}

From source file:es.ua.alex952.main.MainBatch.java

/**
 * Main constructor that parses all arguments from the command line
 * //w w  w  .j  a v  a  2  s  .co m
 * @param args Command line arguments
 */
public MainBatch(String[] args) {

    //Operation creation for usage print      
    Option create = OptionBuilder.withLongOpt("create").withDescription("switch for creating a job")
            .create("c");

    Option daemon = OptionBuilder.withArgName("id").withLongOpt("daemon")
            .withDescription("daemon mode for monitorizing the job after its creation").hasOptionalArg()
            .create("d");

    Option configfile = OptionBuilder.withArgName("config.properties").withLongOpt("configfile")
            .withDescription("the properties config file that has all the program specific configurations")
            .hasArg().create("cf");

    Option parametersfile = OptionBuilder.withArgName("parameters.properties").withLongOpt("parametersfile")
            .withDescription(
                    "properties paramters file that has all the job specific parameters for its creation")
            .hasArg().create("pf");

    Option sourcelanguage = OptionBuilder.withArgName("sl.txt").withLongOpt("sourcelanguage")
            .withDescription("text file containing all the sentences to be translated").hasArg().create("sl");

    Option referencetranslations = OptionBuilder.withArgName("rt.txt").withLongOpt("referencetranslations")
            .withDescription("text file with a translation of reference for each source language sentence")
            .hasArg().create("rt");

    Option gold = OptionBuilder.withArgName("gold.txt").withLongOpt("gold").withDescription(
            "text file with the gold standards given for the job. It has a three lines format that is composed by one line for the source language sentence, one for the reference translation, and the last one for the correct translation")
            .hasArg().create("g");

    Option daemonfrecuency = OptionBuilder.withArgName("daemon frecuency").withLongOpt("daemonfrecuency")
            .withDescription("daemon check frecuency").hasArg().create("df");

    Option help = OptionBuilder.withLongOpt("help").withDescription("shows this help message").create("h");

    options.addOption(create);
    options.addOption(daemon);
    options.addOption(daemonfrecuency);
    options.addOption(configfile);
    options.addOption(parametersfile);
    options.addOption(sourcelanguage);
    options.addOption(referencetranslations);
    options.addOption(gold);
    options.addOption(help);

    //Option parsing
    CommandLineParser clp = new BasicParser();
    try {
        CommandLine cl = clp.parse(options, args);
        if (cl.hasOption("help") || cl.getOptions().length == 0) {
            HelpFormatter hf = new HelpFormatter();
            hf.setWidth(100);
            hf.printHelp("CrowdFlowerTasks", options);
            op = Operation.QUIT;

            return;
        }

        if (cl.hasOption("daemon") && !cl.hasOption("c")) {
            if (cl.getOptionValue("daemon") == null) {
                logger.error("The daemon option must have a job id if it isn't along with create option");
                op = Operation.QUIT;

                return;
            } else if (!cl.hasOption("configfile")) {
                logger.error("The config file is mandatory");
                op = Operation.QUIT;

                return;
            }

            try {
                Integer.parseInt(cl.getOptionValue("daemon"));

                this.id = cl.getOptionValue("daemon");
                this.configFile = cl.getOptionValue("configfile");
                this.op = Operation.DAEMON;

                if (cl.hasOption("daemonfrecuency")) {
                    try {
                        Long l = Long.parseLong(id);
                        this.frecuency = l;
                    } catch (NumberFormatException e) {
                        this.logger.info("The frecuency is not a number. Setting to default: 10 sec");
                    }
                } else {
                    this.logger.info("Daemon frecuency not set. Setting to default: 10 sec");
                }
            } catch (NumberFormatException e) {
                this.logger.error("The id following daemon option must be an integer");
                this.op = Operation.QUIT;

                return;
            }
        } else {
            if (!cl.hasOption("gold") || !cl.hasOption("configfile") || !cl.hasOption("parametersfile")
                    || !cl.hasOption("referencetranslations") || !cl.hasOption("sourcelanguage")) {
                logger.error(
                        "The files gold, tr, lo, config.properties and parameters.properties are mandatory for creating jobs");
                this.op = Operation.QUIT;

                return;
            } else {
                if (cl.hasOption("daemon"))
                    this.daemon = true;
                else {
                    if (cl.hasOption("daemonfrecuency"))
                        this.logger.info(
                                "Daemon frecuency parameter found, ignoring it as there's not a daemon option");
                }

                this.configFile = cl.getOptionValue("configfile");
                this.parametersFile = cl.getOptionValue("parametersfile");
                this.pathGold = cl.getOptionValue("gold");
                this.pathLO = cl.getOptionValue("sourcelanguage");
                this.pathTR = cl.getOptionValue("referencetranslations");

                this.op = Operation.CREATE;
            }
        }

    } catch (ParseException ex) {
        logger.error("Failed argument parsing", ex);
    }
}

From source file:net.hedges.fandangled.commandline.GenericCli.java

public static Options buildOptions() {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("templates")
            .withDescription("the directory containing freemarker templates").hasArg().isRequired()
            .withArgName("directory").create("t"));
    options.addOption(OptionBuilder.withLongOpt("output")
            .withDescription("the directory to which generated files will be outputted").hasArg().isRequired()
            .withArgName("directory").create("o"));
    options.addOption(OptionBuilder.withLongOpt("input").withDescription("the Fandangled IDL to use").hasArg()
            .isRequired().withArgName("idl").create("i"));
    options.addOption(OptionBuilder.withLongOpt("prefix").withDescription("the prefix to give each file name")
            .hasArg().withArgName("prefix").create("p"));
    options.addOption(/*w  w  w  . j  a v a2 s .co  m*/
            OptionBuilder.withLongOpt("extension").withDescription("the extension to give each file name")
                    .hasArg().withArgName("extension").create("e"));
    options.addOption(OptionBuilder.withLongOpt("verbose").withDescription("verbose output").create("v"));
    options.addOption(OptionBuilder.withLongOpt("help").withDescription("display usage").create("h"));
    return options;
}

From source file:de.tudarmstadt.lt.lm.app.PerpDoc.java

/**
 * //from  w w  w. j a v a  2  s.c  o  m
 */
@SuppressWarnings("static-access")
public PerpDoc(String args[]) {
    Options opts = new Options();

    opts.addOption(new Option("?", "help", false, "display this message"));
    opts.addOption(OptionBuilder.withLongOpt("port").withArgName("port-number").hasArg()
            .withDescription(
                    String.format("Specifies the port on which the rmi registry listens (default: %d).",
                            Registry.REGISTRY_PORT))
            .create("p"));
    opts.addOption(OptionBuilder.withLongOpt("selftest")
            .withDescription("Run a selftest, compute perplexity of ngrams in specified LM.").create("s"));
    opts.addOption(OptionBuilder.withLongOpt("quiet").withDescription("Run with minimum outout on stdout.")
            .create("q"));
    opts.addOption(OptionBuilder.withLongOpt("noov").hasOptionalArg().withArgName("{true|false}")
            .withDescription("Do not consider oov terms, i.e. ngrams that end in an oov term. (default: false)")
            .create());
    opts.addOption(OptionBuilder.withLongOpt("oovreflm").withArgName("identifier").hasArg().withDescription(
            "Do not consider oov terms with respect to the provided lm, i.e. ngrams that end in an oov term in the referenced lm. (default use current lm)")
            .create());
    opts.addOption(OptionBuilder.withLongOpt("host").withArgName("hostname").hasArg()
            .withDescription("Specifies the hostname on which the rmi registry listens (default: localhost).")
            .create("h"));
    opts.addOption(OptionBuilder.withLongOpt("file").withArgName("name").hasArg().withDescription(
            "Specify the file or directory that contains '.txt' files that are used as source for testing perplexity with the specified language model. Specify '-' to pipe from stdin. (default: '-').")
            .create("f"));
    opts.addOption(OptionBuilder.withLongOpt("out").withArgName("name").hasArg()
            .withDescription("Specify the output file. Specify '-' to use stdout. (default: '-').")
            .create("o"));
    opts.addOption(OptionBuilder.withLongOpt("name").withArgName("identifier").isRequired().hasArg()
            .withDescription("Specify the name of the language model provider that you want to connect to.")
            .create("i"));

    try {
        CommandLine cmd = new ExtendedGnuParser(true).parse(opts, args);
        if (cmd.hasOption("help"))
            CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, null, 0);

        _host = cmd.getOptionValue("host", "localhost");
        _rmiport = Integer.parseInt(cmd.getOptionValue("port", String.valueOf(Registry.REGISTRY_PORT)));
        _file = cmd.getOptionValue("file", "-");
        _out = cmd.getOptionValue("out", "-");
        _name = cmd.getOptionValue("name");
        _host = cmd.getOptionValue("host", "localhost");
        _selftest = cmd.hasOption("selftest");
        _quiet = cmd.hasOption("quiet");
        _no_oov = cmd.hasOption("noov");
        if (_no_oov && cmd.getOptionValue("noov") != null)
            _no_oov = Boolean.parseBoolean(cmd.getOptionValue("noov"));
        _oovreflm_name = cmd.getOptionValue("oovreflm");

    } catch (Exception e) {
        LOG.error("{}: {}- {}", _rmi_string, e.getClass().getSimpleName(), e.getMessage());
        CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER,
                String.format("%s: %s%n", e.getClass().getSimpleName(), e.getMessage()), 1);
    }
    _rmi_string = String.format("rmi://%s:%d/%s", _host, _rmiport, _name);
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.tools.AerovisConverter.java

@SuppressWarnings("static-access")
@Override/*  www .  ja v  a2  s .c o  m*/
public Options getOptions() {
    Options options = super.getOptions();

    OptionGroup group = new OptionGroup();
    group.setRequired(true);
    group.addOption(OptionBuilder.withLongOpt("problem").hasArg().withArgName("name").create('b'));
    group.addOption(OptionBuilder.withLongOpt("dimension").hasArg().withArgName("number").create('d'));
    options.addOptionGroup(group);

    options.addOption(OptionBuilder.withLongOpt("input").hasArg().withArgName("file").isRequired().create('i'));
    options.addOption(
            OptionBuilder.withLongOpt("output").hasArg().withArgName("file").isRequired().create('o'));
    options.addOption(OptionBuilder.withLongOpt("reduced").create('r'));
    options.addOption(OptionBuilder.withLongOpt("names").hasArg().create('n'));

    return options;
}

From source file:ca.uqac.info.trace.TraceGenerator.java

/**
 * Sets up the options for the command line parser
 * @return The options//from   w w  w .j a  v  a 2 s . c  o  m
 */
@SuppressWarnings("static-access")
private static Options setupOptions() {
    Options options = new Options();
    Option opt;
    opt = OptionBuilder.withLongOpt("help").withDescription("Display command line usage").create("h");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("interval").withArgName("x").hasArg()
            .withDescription("Generate a new message every x milliseconds").create("i");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("verbosity").withArgName("x").hasArg()
            .withDescription("Set verbosity level to x (0 = nothing)").create();
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("generator").withArgName("name").hasArg()
            .withDescription("Use generator name").create("g");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("events").withArgName("n").hasArg()
            .withDescription("Stop after generating n events").create("e");
    options.addOption(opt);
    opt = OptionBuilder.withLongOpt("parameters").withArgName("s").hasArg()
            .withDescription("Pass parameter string s to generator").create();
    options.addOption(opt);
    return options;
}

From source file:benchmarkio.controlcenter.LaunchRocket.java

@SuppressWarnings("static-access")
private static Options initializeOptions() {
    final Options options = new Options();

    options.addOption("u", "usage", false, "show usage");

    // Required options
    options.addOption(OptionBuilder.withLongOpt("broker-type")
            .withDescription("broker type => KAFKA | RABBITMQ | ACTIVEMQ").isRequired().hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("host").withDescription("host of the broker").isRequired()
            .hasArg().create());/* w w  w. jav  a 2s  . co m*/
    options.addOption(OptionBuilder.withLongOpt("port").withDescription("port of the broker").isRequired()
            .hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("num-consumers").withDescription("consumer count").isRequired()
            .hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("num-producers").withDescription("producer count").isRequired()
            .hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("total-number-of-messages")
            .withDescription("total number of messages").isRequired().hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("msg-size-in-kb").withDescription("message size in KB")
            .isRequired().hasArg().create());

    // Optional options
    options.addOption(OptionBuilder.withLongOpt("benchmark-type").withDescription(
            "benchmark type, one of PRODUCER_ONLY | CONSUMER_ONLY | PRODUCER_AND_CONSUMER | PRODUCER_NO_CONSUMER_THEN_CONSUMER. Will default to PRODUCER_AND_CONSUMER, if not specified.")
            .hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("durable")
            .withDescription("boolean value, indicates whether we should test with durability").hasArg()
            .create());
    // Kafka Specific
    options.addOption(OptionBuilder.withLongOpt("zookeeper").withDescription("zookeeperHost:zookeeperPort")
            .hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("kafka-producer-type").withDescription(
            "This parameter specifies whether the messages are sent asynchronously in a background thread. Valid values are (1) async for asynchronous send and (2) sync for synchronous send. By setting the producer to async we allow batching together of requests (which is great for throughput) but open the possibility of a failure of the client machine dropping unsent data. Will default to sync, if not specified.")
            .hasArg().create());

    return options;
}

From source file:edu.bsu.issgame.java.IssGameJava.java

private static Options createCommandLineOptions() {
    // Apache CLI forces the use of a static call to create() here.
    @SuppressWarnings("static-access")
    Option sizeOption = OptionBuilder.withLongOpt(SIZE_OPTION)//
            .withDescription("Specify the size of the display in pixels")//
            .hasArg()//
            .withArgName("res")//
            .create();//from  w  w  w  .  j  a  v  a 2s.  c o  m
    @SuppressWarnings("static-access")
    Option versionOption = OptionBuilder.withLongOpt(VERSIONCODE_OPTION)//
            .withDescription("Specify android manifest version code number.")//
            .hasArg()//
            .withArgName("vCode")//
            .create();
    return new Options().addOption(sizeOption).addOption(versionOption);
}