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:edu.harvard.med.screensaver.io.CommandLineApplication.java

@SuppressWarnings("static-access")
public CommandLineApplication(String[] cmdLineArgs) {
    _cmdLineArgs = cmdLineArgs;/* w w  w  .  j  av  a  2s.co  m*/
    _options = new Options();
    _options.addOption(OptionBuilder.withLongOpt("help").withDescription("print this help").create("h"));
}

From source file:com.continuent.tungsten.common.security.KeystoreManagerCtrl.java

/**
 * Setup command line options/*from   w  w w  . java2s  .  c  om*/
 */
@SuppressWarnings("static-access")
private void setupCommandLine() {
    // --- Options on the command line ---
    Option help = OptionBuilder.withLongOpt(HELP).withDescription("Displays this message").create(_HELP);

    // Mutually excluding options
    OptionGroup optionGroup = new OptionGroup();
    check = OptionBuilder.withLongOpt(CHECK).hasArgs(0).withDescription("Checks key password inside a keystore")
            .create(_CHECK);

    optionGroup.addOption(check);
    optionGroup.setRequired(true); // At least 1 command required

    // --- Options replacing parameters from security.properties ---
    Option keystoreLocation = OptionBuilder.withLongOpt(KEYSTORE_LOCATION).withArgName("filename").hasArg()
            .withDescription("Location of the keystore file").isRequired().create(_KEYSTORE_LOCATION);
    Option keyAlias = OptionBuilder.withLongOpt(KEY_ALIAS).withArgName("key alias").hasArg().isRequired()
            .withDescription("Alias for the key").create(_KEY_ALIAS);
    Option keyType = OptionBuilder.withLongOpt(KEY_TYPE).withArgName("key type").hasArg().isRequired()
            .withDescription(MessageFormat.format("Type of key: {0}", KEYSTORE_TYPE.getListValues("|")))
            .create(_KEY_TYPE);

    Option keystorePassword = OptionBuilder.withLongOpt(KEYSTORE_PASSWORD).withArgName("password").hasArg()
            .withDescription("Password for the keystore file").create(_KEYSTORE_PASSWORD);
    Option keyPassword = OptionBuilder.withLongOpt(KEY_PASSWORD).withArgName("key password").hasArg()
            .withDescription("Password for the key").create(_KEY_PASSWORD);

    // --- Add options to the list ---
    // --- Help
    this.helpOptions.addOption(help);

    // --- Program command line options
    this.options.addOptionGroup(optionGroup);
    this.options.addOption(help);
    this.options.addOption(keystoreLocation);
    this.options.addOption(keyAlias);
    this.options.addOption(keyType);
    this.options.addOption(keystorePassword);
    this.options.addOption(keyPassword);
}

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

@SuppressWarnings("static-access")
@Override/*w  ww. j  a  v a  2s .  c  o m*/
public Options getOptions() {
    Options options = super.getOptions();

    options.addOption(
            OptionBuilder.withLongOpt("output").hasArg().withArgName("file").isRequired().create('f'));
    options.addOption(OptionBuilder.withLongOpt("problem").hasArg().withArgName("name").create('b'));
    options.addOption(
            OptionBuilder.withLongOpt("algorithm").hasArg().withArgName("name").isRequired().create('a'));
    options.addOption(OptionBuilder.withLongOpt("properties").hasArgs().withArgName("p1=v1;p2=v2;...")
            .withValueSeparator(';').create('x'));
    options.addOption(OptionBuilder.withLongOpt("seed").hasArg().withArgName("value").create('s'));
    options.addOption(OptionBuilder.withLongOpt("epsilon").hasArg().withArgName("e1,e2,...").create('e'));
    options.addOption(OptionBuilder.withLongOpt("numberOfEvaluations").hasArg().withArgName("value")
            .isRequired().create('n'));
    options.addOption(OptionBuilder.withLongOpt("runtimeFrequency").hasArg().withArgName("value").create('F'));
    options.addOption(OptionBuilder.withLongOpt("variables").hasArg().withArgName("v1,v2,...").create('v'));
    options.addOption(OptionBuilder.withLongOpt("objectives").hasArg().withArgName("value").create('o'));
    options.addOption(OptionBuilder.withLongOpt("constraints").hasArg().withArgName("value").create('c'));
    options.addOption(OptionBuilder.withLongOpt("lowerBounds").hasArg().withArgName("v1,v2,...").create("l"));
    options.addOption(OptionBuilder.withLongOpt("upperBounds").hasArg().withArgName("v1,v2,...").create('u'));

    options.addOption(OptionBuilder.withLongOpt("useSocket").create('S'));
    options.addOption(OptionBuilder.withLongOpt("hostname").hasArg().withArgName("value").create('H'));
    options.addOption(OptionBuilder.withLongOpt("port").hasArg().withArgName("value").create('P'));
    options.addOption(OptionBuilder.withLongOpt("startupDelay").hasArg().withArgName("value").create('D'));

    options.addOption(OptionBuilder.withLongOpt("test").hasOptionalArg().withArgName("trials").create('t'));

    return options;
}

From source file:BasApp.java

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

    options.addOption("h", "help", false, "print this message");

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("config").withDescription("use configuration file for backup")
            .hasArg().withArgName("XML").create("c"));

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("dump-config")
            .withDescription("write configuration file for backup").hasArg().withArgName("XML").create());

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("repository").withDescription("path to backup repository")
            .hasArg().withArgName("PATH").create("p"));

    //noinspection AccessStaticViaInstance
    options.addOption(/*from ww  w .  j av a  2 s  . c  o  m*/
            OptionBuilder.withLongOpt("passwd").withDescription("paassword for AES encryption/decryption data")
                    .hasArg().withArgName("PASSWD").create());

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("passwd-meta")
            .withDescription("paassword for AES encryption/decryption metadata (index of backuped files)")
            .hasArg().withArgName("PASSWD").create());

    /**************************************************************/

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("backup").withDescription("create new backup of paths with ID")
            .hasArg().withArgName("ID").create("b"));

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("exclude")
            .withDescription("(only backup) exclude files with wildcard pattern ie: *.tmp *.bak").hasArgs()
            .withArgName("PATERNS").create());

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("exclude-dir")
            .withDescription("(only backup) exclude subdirectories with wildcard pattern").hasArgs()
            .withArgName("PATERNS").create());

    /**************************************************************/

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("restore").withDescription("restore data from selected index")
            .hasArg().withArgName("IDX").create("r"));

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("restore-to")
            .withDescription("restore data to another path (tree structure is preserved)").hasArg()
            .withArgName("TARGET_PATH").create());

    /**************************************************************/

    //noinspection AccessStaticViaInstance
    options.addOption(OptionBuilder.withLongOpt("check")
            .withDescription("check exists data from index (can use wildcard in index name)").hasOptionalArg()
            .withArgName("IDX").create());

    // TODO Lebeda - --check check if exists all data files used in backup indexes
    // TODO Lebeda - checksum check if exists and are readable all data files used in backup indexes
    // TODO Lebeda - clear delete datafiles which not linked from any indexes

    /**************************************************************/

    // TODO Lebeda - -l --log <ID> <PATERN> list all files contains PATERN from indexes files for ID
    // TODO Lebeda - --list <ID> list all indexes for ID

    /**************************************************************/
    // TODO Lebeda - delete <IDX> delete the index files
    // TODO Lebeda - use automatic hostname as ID InetAddress.getLocalHost().getHostName()

    return options;
}

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

@SuppressWarnings("static-access")
public StartLM(String[] args) {
    Options opts = new Options();
    opts.addOption(new Option("?", "help", false, "display this message"));
    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("rmiport").withArgName("port-number").hasArg()
            .withDescription(String.format("specifies the port on which rmi registry listens (default: %d)",
                    Registry.REGISTRY_PORT))
            .create("rp"));
    opts.addOption(OptionBuilder.withLongOpt("port").withArgName("port-number").hasArg().withDescription(
            "specifies the port on which this service should populate (default: 0, which means a random port will be assigned)")
            .create("p"));
    opts.addOption(OptionBuilder.withLongOpt("lmtype").withArgName("class").hasArg().withDescription(
            "specify the instance of the language model that you want to use: {BerkeleyLM, CountingLM, LaplaceSmoothedLM, CountingStringLM, KneserNeyLM, (experimental: KneserNeyLMRecursive, PoptKneserNeyLMRecursive, ModifiedKNeserNeyLMRecursive)} (default: BerkeleyLM)")
            .create("t"));
    opts.addOption(OptionBuilder.withLongOpt("ptype").withArgName("class").hasArg().withDescription(
            "specify the instance of the language model provider that you want to use: {LtSegProvider, BreakIteratorStringProvider, PreTokenizedStringProvider} (default: LtSegProvider)")
            .create("pt"));
    opts.addOption(OptionBuilder.withLongOpt("dir").withArgName("directory").isRequired().hasArg()
            .withDescription(/*from   w  w w .j a v  a 2 s.c o m*/
                    "specify the directory that contains '.txt' files that are used as source for this language model")
            .create("d"));
    opts.addOption(OptionBuilder.withLongOpt("order").withArgName("ngram-order").hasArg()
            .withDescription("specify the order for this language model").create("n"));
    opts.addOption(OptionBuilder.withLongOpt("identifier").withArgName("name").hasArg().withDescription(
            "specify a name/identifier for the language model. If no name is given, a random name will be generated.")
            .create("i"));
    opts.addOption(OptionBuilder.withLongOpt("overwrite")
            .withDescription("Overwrite existing saved or temporary files.").create("w"));
    opts.addOption(OptionBuilder.withLongOpt("discount").withArgName("Discount value in [0,1]").hasArg()
            .withDescription("Uniform discount value for Lucene based Kneser-Ney LM.").create());
    opts.addOption(OptionBuilder.withLongOpt("mincount").withArgName("int").hasArg().withDescription(
            "(Only applicable for Lucene Based LMs) - Specify the number of times an ngram must occur to be considered in further calculations. Ngrams with counts below mincount are filtered. (default: 1).")
            .create("m"));

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

        _rmiRegistryPort = Integer
                .parseInt(cmd.getOptionValue("rmiport", String.valueOf(Registry.REGISTRY_PORT)));
        _port = Integer.parseInt(cmd.getOptionValue("port", "0"));
        _srcdir = cmd.getOptionValue("dir");
        _n = Integer.parseInt(cmd.getOptionValue("order", "5"));
        _type_lm = cmd.getOptionValue("lmtype", BerkeleyLM.class.getSimpleName());
        _type_provider = cmd.getOptionValue("ptype", LtSegProvider.class.getSimpleName());
        _name = cmd.getOptionValue("identifier", String.valueOf(System.currentTimeMillis()));
        _host = cmd.getOptionValue("host", "localhost");
        _overwrite = cmd.hasOption("overwrite");
        _discount = Double.parseDouble(cmd.getOptionValue("discount", "-1"));
        _mincount = Integer.parseInt(cmd.getOptionValue("mincount", "1"));
        // String[] non_named_args = cmd.getArgs();
        _providerJmxBeanName = new ObjectName("de.tudarmstadt.lt.lm:type=ProviderService");

    } catch (Exception e) {
        LOG.error("{}: {}", 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);
    }
}

From source file:com.splunk.Command.java

@SuppressWarnings("static-access") // OptionBuilder API requires this
public Command addRule(String name, Class argType, String description) {
    rules.addOption(OptionBuilder.withLongOpt(name).hasArg(true).withType(argType).withDescription(description)
            .create());/*from w  w  w .  ja  va  2  s  .  c  om*/
    return this;
}

From source file:com.github.houbie.lesscss.LesscCommandLineParser.java

@SuppressWarnings("static-access")
private static org.apache.commons.cli.Options createOptions() {
    org.apache.commons.cli.Options result = new org.apache.commons.cli.Options();

    result.addOption("h", HELP_OPTION, false, "Print help (this message) and exit.");
    result.addOption(OptionBuilder.withLongOpt(INCLUDE_PATH_OPTION).hasArg()
            .withDescription("Set include paths. Separated by `:'. Use `;' on Windows.").create());
    result.addOption("M", DEPENDS_OPTION, false, "Output a makefile import dependency list to stdout.");
    result.addOption(OptionBuilder.withLongOpt(NO_IE_COMPAT_OPTION)
            .withDescription("Disable IE compatibility checks.").create());
    result.addOption(OptionBuilder.withLongOpt(NO_JS_OPTION).withDescription("Disable JavaScript in less files")
            .create());//from   w w  w .  j  a va 2s  . c  o m
    result.addOption("l", LINT_OPTION, false, "Syntax check only (lint).");
    result.addOption("s", SILENT_OPTION, false, "Suppress output of error messages.");
    result.addOption(OptionBuilder.withLongOpt(STRICT_IMPORTS_OPTION)
            .withDescription("Force evaluation of imports.").create());
    result.addOption("v", VERSION_OPTION, false, "Print version number and exit.");
    result.addOption("x", COMPRESS_OPTION, false, "Compress output by removing some whitespaces.");
    result.addOption(OptionBuilder.withLongOpt(SOURCE_MAP_OPTION).hasOptionalArg()
            .withDescription(
                    "--source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map)")
            .create());
    result.addOption(OptionBuilder.withLongOpt(SOURCE_MAP__ROOTPATH_OPTION).hasArg()
            .withDescription("adds this path onto the sourcemap filename and less file paths").create());
    result.addOption(OptionBuilder.withLongOpt(SOURCE_MAP__BASEPATH_OPTION).hasArg()
            .withDescription("Sets sourcemap base path, defaults to current working directory.").create());
    result.addOption(OptionBuilder.withLongOpt(SOURCE_MAP_LESS_INLINE_OPTION)
            .withDescription("puts the less files into the map instead of referencing them").create());
    result.addOption(OptionBuilder.withLongOpt(SOURCE_MAP_MAP_INLINE_OPTION)
            .withDescription("puts the map (and any less files) into the output css file").create());
    result.addOption(OptionBuilder.withLongOpt(SOURCE_MAP_URL_OPTION).hasArg()
            .withDescription("the complete url and filename put in the less file").create());
    result.addOption("rp", ROOT_PATH_OPTION, true,
            "Set rootpath for url rewriting in relative imports and urls. Works with or without the relative-urls option.");
    result.addOption("ru", RELATIVE_URLS_OPTION, false, "re-write relative urls to the base less file.");
    result.addOption("sm", STRICT_MATH_OPTION, false,
            "Turn on or off strict math, where in strict mode, math requires brackets. This option may default to on and then be removed in the future.");
    result.addOption("su", STRICT_UNITS_OPTION, false,
            "Allow mixed units, e.g. 1px+1em or 1px*1px which have units that cannot be represented.");
    result.addOption(OptionBuilder.withLongOpt(GLOBAL_VAR_OPTION).hasArg()
            .withDescription("--global-var='VAR=VALUE' Defines a variable that can be referenced by the file.")
            .create());
    result.addOption(OptionBuilder.withLongOpt(MODIFY_VAR_OPTION).hasArg()
            .withDescription("--modify-var='VAR=VALUE' Modifies a variable already declared in the file.")
            .create());
    result.addOption(OptionBuilder.withLongOpt(VERBOSE_OPTION).withDescription("Be verbose.").create());
    result.addOption(OptionBuilder.withLongOpt(YUI_COMPRESS_OPTION)
            .withDescription("Compress output using YUI cssmin.").create());

    //deprecated options
    result.addOption(OptionBuilder.hasArg().withLongOpt(OPTIMIZATION_LEVEL_OPTION).withType(Number.class)
            .withDescription(
                    "[deprecated] -O0, -O1, -O2; Set the parser's optimization level. The lower the number, the less nodes it will create in the tree. This could matter for debugging, or if you want to access the individual nodes in the tree.")
            .create('O'));
    result.addOption(OptionBuilder.withLongOpt(LINE_NUMBERS_OPTION).hasArg().withDescription(
            "[deprecated] --line-numbers=TYPE Outputs filename and line numbers. TYPE can be either 'comments', which will output the debug info within comments, 'mediaquery' that will output the information within a fake media query which is compatible with the SASS format, and 'all' which will do both.")
            .create());

    //additional lesscss options
    result.addOption("js", CUSTOM_JS_OPTION, true, "File with custom JavaScript functions.");
    result.addOption("e", ENCODING_OPTION, true, "Character encoding.");
    result.addOption(
            OptionBuilder.withLongOpt(CACHE_DIR_OPTION).hasArg().withDescription("Cache directory.").create());
    result.addOption(
            OptionBuilder.withLongOpt(DAEMON_OPTION).withDescription("Start compiler daemon.").create());
    result.addOption(OptionBuilder.hasArg().withLongOpt(ENGINE_OPTION)
            .withDescription(
                    "JavaScript engine, either 'rhino' (default), 'nashorn' (requires JDK8) or 'commandline'.")
            .create());

    return result;
}

From source file:gov.nih.nci.grididloader.BigIdCreator.java

/**
  * Main program./*ww w . ja v a2  s.  c  om*/
  * Two mutually exclusive command line options are possible:
  * -I include the following entities
  * -E exclude the following entities
  * The entities are passed as a space delimited list like:
  * -I Taxon Cytoband
 * @param args
 */
public static void main(String[] args) throws Exception {

    String[] classFilter = null;
    boolean isInclude = true;

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("include").withDescription("classes to include")
            .hasOptionalArgs().create("I"));

    options.addOption(OptionBuilder.withLongOpt("exclude").withDescription("classes to exclude")
            .hasOptionalArgs().create("E"));

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
    String[] include = cmd.getOptionValues("I");
    String[] exclude = cmd.getOptionValues("E");

    if (include != null) {
        if (exclude != null)
            argError();
        isInclude = true;
        classFilter = include;
    } else if (exclude != null) {
        if (include != null)
            argError();
        isInclude = false;
        classFilter = exclude;
    }

    long start = System.currentTimeMillis();
    BigIdCreator loader = new BigIdCreator();
    loader.createAndUpdate(classFilter, isInclude);
    //loader.printSQL();
    long stop = System.currentTimeMillis();
    System.err.println("All updates took " + (float) (stop - start) / 60000 + " min.");
}

From source file:groovy.ui.InteractiveShell.java

/**
 * Process cli args when the shell is invoked via main().
 *
 * @noinspection AccessStaticViaInstance
 *///from w w  w  . j av a 2  s.  c om
private static void processCommandLineArguments(final String[] args) throws Exception {
    assert args != null;

    //
    // TODO: Let this take a single, optional argument which is a file or URL to run?
    //

    Options options = new Options();

    options.addOption(OptionBuilder.withLongOpt("help")
            .withDescription(MESSAGES.getMessage("cli.option.help.description")).create('h'));

    options.addOption(OptionBuilder.withLongOpt("version")
            .withDescription(MESSAGES.getMessage("cli.option.version.description")).create('V'));

    //
    // TODO: Add more options, maybe even add an option to prime the buffer from a URL or File?
    //

    //
    // FIXME: This does not currently barf on unsupported options short options, though it does for long ones.
    //        Same problem with commons-cli 1.0 and 1.1
    //

    CommandLineParser parser = new PosixParser();
    CommandLine line = parser.parse(options, args, true);
    String[] lineargs = line.getArgs();

    // Puke if there were arguments, we don't support any right now
    if (lineargs.length != 0) {
        System.err.println(MESSAGES.format("cli.info.unexpected_args",
                new Object[] { DefaultGroovyMethods.join(lineargs, " ") }));
        System.exit(1);
    }

    PrintWriter writer = new PrintWriter(System.out);

    if (line.hasOption('h')) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(writer, 80, // width
                "groovysh [options]", "", options, 4, // left pad
                4, // desc pad
                "", false); // auto usage

        writer.flush();
        System.exit(0);
    }

    if (line.hasOption('V')) {
        writer.println(MESSAGES.format("cli.info.version", new Object[] { InvokerHelper.getVersion() }));
        writer.flush();
        System.exit(0);
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.CommandLineUtility.java

/**
 * Returns the options made available by this command line utility. The
 * base implementation automatically provides the {@code -h,--help} option.
 * Implementations overriding this method and begin with a call to
 * {@code super.getOptions()}.//from w  ww .j  a  va 2s. c om
 * 
 * @return the options made available by this command line utility
 */
@SuppressWarnings("static-access")
public Options getOptions() {
    Options options = new Options();

    options.addOption(OptionBuilder.withLongOpt("help").create('h'));

    return options;
}