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:de.tudarmstadt.lt.lm.app.LineProbPerp.java

@SuppressWarnings("static-access")
public LineProbPerp(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(// w ww.  j  av a  2  s .  c om
                    String.format("Specifies the port on which the rmi registry listens (default: %d).",
                            Registry.REGISTRY_PORT))
            .create("rp"));
    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"));
    opts.addOption(OptionBuilder.withLongOpt("runparallel")
            .withDescription("Specify if processing should happen in parallel.").create("p"));

    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");
        _parallel = cmd.hasOption("runparallel");

    } catch (Exception e) {
        LOG.error("{}: {}- {}", _rmi_string, e.getClass().getSimpleName(), e.getMessage());
        CliUtils.print_usage_quit(System.err, getClass().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:de.topobyte.utilities.apache.commons.cli.OptionHelper.java

/**
 * Add a long option to the options specified by parameters
 * //from www.ja v a 2 s .c  o m
 * @param options
 *            the options to add to.
 * @param longName
 *            the long option name.
 * @param hasArg
 *            whether it expects an argument
 * @param required
 *            whether this is a required option.
 * @param description
 *            the option description
 * @return the Option object created.
 */
public static Option addL(Options options, String longName, boolean hasArg, boolean required,
        String description) {
    Option option = new Option(null, longName, hasArg, description);
    option.setRequired(required);
    options.addOption(option);
    return option;
}

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

/**
 * //from  ww  w. ja  v  a2  s  .  c o  m
 */
@SuppressWarnings("static-access")
public PerplexityClient(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("skipoov").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("skipoovreflm").hasOptionalArg().withArgName("{true|false}")
            .withDescription(
                    "Do not consider oov terms regarding the oovreflm, 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("id").withArgName("identifier").isRequired().hasArg()
            .withDescription("Specify the name of the language model provider that you want to connect to.")
            .create("i"));
    opts.addOption(OptionBuilder.withLongOpt("one_ngram_per_line").hasOptionalArg().withArgName("{true|false}")
            .withDescription(
                    "Specify if the input file contains one ngram per line or sentences. (default: false)")
            .create());

    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", "-");
        _id = cmd.getOptionValue("id");
        _host = cmd.getOptionValue("host", "localhost");
        _selftest = cmd.hasOption("selftest");
        _quiet = cmd.hasOption("quiet");
        _no_oov = cmd.hasOption("skipoov");
        if (_no_oov && cmd.getOptionValue("skipoov") != null)
            _no_oov = Boolean.parseBoolean(cmd.getOptionValue("skipoov"));
        _no_oov_reflm = cmd.hasOption("skipoovreflm");
        if (_no_oov_reflm && cmd.getOptionValue("skipoovreflm") != null)
            _no_oov_reflm = Boolean.parseBoolean(cmd.getOptionValue("skipoovreflm"));

        _one_ngram_per_line = cmd.hasOption("one_ngram_per_line");
        if (_one_ngram_per_line && cmd.getOptionValue("one_ngram_per_line") != null)
            _one_ngram_per_line = Boolean.parseBoolean(cmd.getOptionValue("one_ngram_per_line"));
        _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, _id);
}

From source file:is.hi.bok.deduplicator.CommandLineParser.java

/**
 * Constructor./*from   www .j a  v  a2  s .  com*/
 *
 * @param args Command-line arguments to process.
 * @param out PrintStream to write on.
 * @throws ParseException Failed parse of command line.
 */
public CommandLineParser(String[] args, PrintWriter out) throws ParseException {
    super();

    this.out = out;

    this.options = new Options();
    this.options.addOption(new Option("h", "help", false, "Prints this message and exits."));

    Option opt = new Option("o", "mode", true, "Index by URL, HASH or BOTH. Default: BOTH.");
    opt.setArgName("type");
    this.options.addOption(opt);

    this.options.addOption(new Option("s", "equivalent", false,
            "Include a stripped URL in the index for equivalent URL " + "matches."));

    this.options.addOption(new Option("t", "timestamp", false, "Include the time of fetch in the index."));

    this.options.addOption(
            new Option("e", "etag", false, "Include etags in the index (if available in the source)."));

    opt = new Option("m", "mime", true,
            "A filter on what mime types are added into the index " + "(blacklist). Default: ^text/.*");
    opt.setArgName("reg.expr.");
    this.options.addOption(opt);

    this.options.addOption(
            new Option("w", "whitelist", false, "Make the --mime filter a whitelist instead of blacklist."));

    opt = new Option("i", "iterator", true,
            "An iterator suitable for the source data (default iterator " + "works on Heritrix's crawl.log).");
    opt.setArgName("classname");
    this.options.addOption(opt);

    this.options.addOption(new Option("a", "add", false, "Add source data to existing index."));

    opt = new Option("r", "origin", true,
            "If set, the 'origin' of each URI will be added to the index."
                    + " If no origin is provided by the source data then the "
                    + "argument provided here will be used.");
    opt.setArgName("origin");
    this.options.addOption(opt);

    this.options.addOption(new Option("d", "skip-duplicates", false,
            "If set, URIs marked as duplicates will not be added to the " + "index."));

    PosixParser parser = new PosixParser();
    try {
        this.commandLine = parser.parse(this.options, args, false);
    } catch (UnrecognizedOptionException e) {
        usage(e.getMessage(), 1);
    }
}

From source file:de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.annotation.CommandAnnotationProcessor.java

private void addOptions(final Command cmd) throws CommandAnnotationProcessorException {
    final List<Field> fields = getFields(cmd.getClass());

    for (final Field field : fields) {
        final CommandOption annotation = field.getAnnotation(CommandOption.class);

        if (annotation != null) {
            final String longOpt = annotation.longOptionName().equals("") ? null : annotation.longOptionName();

            Option option = new Option(annotation.shortOptionName(), longOpt, annotation.hasArgument(),
                    annotation.description());

            if (annotation.hasArgument()) {
                option.setArgName(annotation.argumentName());
            } else {
                if (!field.getType().equals(Boolean.class)) {
                    throw new CommandAnnotationProcessorException(
                            "If the Option has no argument, the field must be of type boolean.");
                }/*from  w w w  . j  a  va 2s .c o  m*/
            }

            option.setOptionalArg(annotation.optionalArgument());

            cmd.addOption(option);
        }
    }
}

From source file:il.ac.tau.yoavram.pes.PesCommandLineParser.java

@SuppressWarnings("static-access")
private static Options createOptions() {
    Options options = new Options();
    Option xml = OptionBuilder.withArgName("file").hasArg().isRequired(true).withLongOpt("xml")
            .withDescription("Spring XML configuration file").create(OptCode.Xml.toString());
    Option log = OptionBuilder.withArgName("file").hasArg().withLongOpt("log")
            .withDescription("log4j config filename").create(OptCode.Log.toString());
    Option pfile = OptionBuilder.withArgName("file").hasArg().withLongOpt("pfile")
            .withDescription("properties filename").create(OptCode.FileProperties.toString());
    Option properties = OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator()
            .withDescription("properties (override properties file)").withLongOpt("properties")
            .create(OptCode.Properties.toString());
    Option help = new Option(OptCode.Help.toString(), "help", false, "print this message");

    options.addOption(xml).addOption(pfile).addOption(log).addOption(properties).addOption(help);
    return options;
}

From source file:com.alibaba.rocketmq.tools.command.consumer.ConsumerProgressSubCommand.java

@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("g", "groupName", true, "consumer group name");
    opt.setRequired(false);//from  w  w  w  .  j a v  a 2s.c  o m
    options.addOption(opt);

    return options;
}

From source file:lu.uni.adtool.tools.Clo.java

public Clo() {
    this.options = new org.apache.commons.cli.Options();
    this.options.addOption("h", "help", false, Options.getMsg("clo.help.txt"));
    this.options.addOption("v", "version", false, Options.getMsg("clo.version.txt"));
    //     this.options.addOption("a", "all-domains", false, Options.getMsg("clo.allDomains.txt"));
    this.options.addOption("D", "no-derived", false, Options.getMsg("clo.derived.txt"));
    this.options.addOption("m", "mark-editable", false, Options.getMsg("clo.markEditable.txt"));
    this.options.addOption("L", "no-labels", false, Options.getMsg("clo.labels.txt"));
    this.options.addOption("C", "no-computed", false, Options.getMsg("clo.computed.txt"));
    // this.options.addOption("r", "rank", false,
    // Options.getMsg("clo.rank.txt"));

    Option option = new Option("o", "open", true, Options.getMsg("clo.open.txt"));
    // Set option c to take 1 to oo arguments
    option.setArgs(Option.UNLIMITED_VALUES);
    option.setArgName("file_1>...<file_N");
    this.options.addOption(option);
    option = new Option("i", "import", true, Options.getMsg("clo.import.txt"));
    option.setArgName("file");
    this.options.addOption(option);
    option = new Option("x", "export", true, Options.getMsg("clo.export.txt"));
    option.setArgName("file");
    this.options.addOption(option);
    option = new Option("d", "domain", true, Options.getMsg("clo.domain.txt"));
    //     option.setValueSeparator(',');
    //     option.setArgs(1);
    option.setArgName("domainID");
    this.options.addOption(option);
    option = new Option("r", "rank", true, Options.getMsg("clo.rank.txt"));
    option.setArgs(1);//from  w ww .j  a v  a2s  . c  om
    option.setArgName("rankNo");
    this.options.addOption(option);
    option = new Option("s", "size", true, Options.getMsg("clo.size.txt"));
    option.setArgs(1);
    option.setArgName("X>x<Y");
    this.options.addOption(option);
    this.toOpen = null;
}

From source file:com.google.enterprise.connector.encryptpassword.EncryptPassword.java

@Override
public Options getOptions() {
    Options options = super.getOptions();
    Option option = new Option("p", "password", true, "Encrypt the supplied password.");
    option.setArgName("password");
    options.addOption(option);//from   w w w.j a v a 2s  .c  o  m
    return options;
}

From source file:jrrombaldo.pset.PSETMain.java

private static Options prepareOptions() {
    Options options = new Options();

    Option help = new Option("h", "help", false, "Show usage help");
    options.addOption(help);/* w ww  .j a va 2 s .  co  m*/

    Option cli = new Option("c", "cli", false, "Use CLI mode, otherwise will start GUI mode");
    options.addOption(cli);

    // OptionGroup searchEngine = new OptionGroup();
    Option google = new Option("g", "google", false, "Use google search engine");
    Option bing = new Option("b", "bing", false, "Use bing search engine");
    // searchEngine.addOption(google).addOption(bing);
    // searchEngine.setRequired(true);
    // options.addOptionGroup(searchEngine);
    options.addOption(google).addOption(bing);

    Option domain = new Option("d", "domain", true, "Target domain");
    // domain.setRequired(true);
    options.addOption(domain);

    Option proxy = new Option("p", "proxy", true, "Use HTTP proxy format: host:port");
    options.addOption(proxy);

    return options;
}