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:com.linkedin.helix.webapp.RestAdminApplication.java

@SuppressWarnings("static-access")
private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(HELP).withDescription("Prints command-line options info")
            .create();//from w ww  . j  a v a2s .  c  om
    helpOption.setArgs(0);
    helpOption.setRequired(false);
    helpOption.setArgName("print help message");

    Option zkServerOption = OptionBuilder.withLongOpt(ZKSERVERADDRESS)
            .withDescription("Provide zookeeper address").create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required)");

    Option portOption = OptionBuilder.withLongOpt(PORT).withDescription("Provide web service port").create();
    portOption.setArgs(1);
    portOption.setRequired(false);
    portOption.setArgName("web service port, default: " + DEFAULT_PORT);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(zkServerOption);
    options.addOption(portOption);

    return options;
}

From source file:com.linkedin.helix.examples.BootstrapProcess.java

@SuppressWarnings("static-access")
private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();/*from  w ww  . j  a  va2s.co  m*/

    Option zkServerOption = OptionBuilder.withLongOpt(zkServer).withDescription("Provide zookeeper address")
            .create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required)");

    Option clusterOption = OptionBuilder.withLongOpt(cluster).withDescription("Provide cluster name").create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name (Required)");

    Option hostOption = OptionBuilder.withLongOpt(hostAddress).withDescription("Provide host name").create();
    hostOption.setArgs(1);
    hostOption.setRequired(true);
    hostOption.setArgName("Host name (Required)");

    Option portOption = OptionBuilder.withLongOpt(hostPort).withDescription("Provide host port").create();
    portOption.setArgs(1);
    portOption.setRequired(true);
    portOption.setArgName("Host port (Required)");

    Option stateModelOption = OptionBuilder.withLongOpt(stateModel).withDescription("StateModel Type").create();
    stateModelOption.setArgs(1);
    stateModelOption.setRequired(true);
    stateModelOption.setArgName("StateModel Type (Required)");

    // add an option group including either --zkSvr or --configFile
    Option fileOption = OptionBuilder.withLongOpt(configFile)
            .withDescription("Provide file to read states/messages").create();
    fileOption.setArgs(1);
    fileOption.setRequired(true);
    fileOption.setArgName("File to read states/messages (Optional)");

    Option transDelayOption = OptionBuilder.withLongOpt(transDelay).withDescription("Provide state trans delay")
            .create();
    transDelayOption.setArgs(1);
    transDelayOption.setRequired(false);
    transDelayOption.setArgName("Delay time in state transition, in MS");

    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(zkServerOption);
    optionGroup.addOption(fileOption);

    Options options = new Options();
    options.addOption(helpOption);
    // options.addOption(zkServerOption);
    options.addOption(clusterOption);
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(stateModelOption);
    options.addOption(transDelayOption);

    options.addOptionGroup(optionGroup);

    return options;
}

From source file:com.netspective.sparx.navigate.NavigationControllerServletOptions.java

public void initOptions() {
    servletOptions.addOption(OptionBuilder.withLongOpt("help").withDescription("Show options").create('?'));

    servletOptions.addOption(OptionBuilder.withLongOpt("project").hasArg().withArgName("file")
            .withDescription("The project file to use. The default is " + DEFAULT_PROJECT_FILE_NAME)
            .create('p'));

    servletOptions.addOption(OptionBuilder.withLongOpt("project-component-class").hasArg().withArgName("name")
            .withDescription("The name of the class used for the ProjectComponent instance. Default is "
                    + PROJECT_COMPONENT_CLASS.getName() + ".")
            .create('P'));

    servletOptions.addOption(OptionBuilder.withLongOpt("runtime-environment").hasArg().withArgName("flags")
            .withDescription(//  w  w  w . jav  a  2s.  c  om
                    "The runtime environment flags to use. The default is " + DEFAULT_RUNTIME_FLAGS + ".")
            .create('e'));

    servletOptions.addOption(OptionBuilder.withLongOpt("runtime-environment-class").hasArg().withArgName("name")
            .withDescription("The class used for the RuntimeEnvironmentFlags instance. The default is "
                    + RUNTIME_ENVIRONMENT_FLAGS_CLASS.getName() + ".")
            .create('E'));

    servletOptions.addOption(OptionBuilder.withLongOpt("navigation-tree").hasArg().withArgName("name")
            .withDescription(
                    "The name of navigation tree (defined in <project>) to use for navigation. The default is specified in the project file as <navigation-tree default=\"yes\">.")
            .create('n'));

    servletOptions.addOption(OptionBuilder.withLongOpt("theme").hasArg().withArgName("name").withDescription(
            "The name of theme (defined in <project>) to use for presentation. The default is specified in the project file as <theme default=\"yes\">.")
            .create('t'));

    servletOptions
            .addOption(OptionBuilder.withLongOpt("sparx-resource-locators").hasArg().withArgName("locators")
                    .withDescription(
                            "A set of comma-separated locators for finding Sparx web resources. Default is "
                                    + DEFAULT_SPARX_RESOURCES_LOCATOR)
                    .create('s'));

    servletOptions.addOption(OptionBuilder.withLongOpt("login-manager").hasArg().withArgName("name")
            .withDescription(
                    "The name of the login manager (defined in <project>) to use for security. There is no security by default.")
            .create('l'));

    servletOptions.addOption(OptionBuilder.withLongOpt("logout-request-param-name").hasArg().withArgName("name")
            .withDescription(
                    "The name of the servlet request parameter that will be set if when a users wants to logout. The default is \""
                            + DEFAULT_LOGOUT_REQ_PARAM + "\".")
            .create('L'));

    servletOptions.addOption(OptionBuilder.withLongOpt("init-first-time-using-ant").hasArg()
            .withArgName("file:target")
            .withDescription(
                    "Initialize the servlet using an Ant build file and a given target the first time the servlet is initialized.")
            .create('I'));

    servletOptions.addOption(OptionBuilder.withLongOpt("init-using-ant").hasArg().withArgName("file:target")
            .withDescription(
                    "Initialize the servlet using an Ant build file and a given target. This build file and target will always be executed each time the servlet is initialized (and if a init-first-time-using-ant option is provided, it will be run after that file:target too).")
            .create('i'));

    servletOptions.addOption(OptionBuilder.withLongOpt("init-using-ant-log").hasArg().withArgName("file")
            .withDescription(
                    "The name of the log file to store ant init output (defaults to location of ant file)")
            .create('B'));

    servletOptions.addOption(OptionBuilder.withLongOpt("init-success").hasArg().withArgName("type")
            .withDescription(
                    "Determine when the initialization will be considered successful (to increment the init count). Options are END_INIT which means at the end of the Servlet init() method or FIRST_GET_POST which means at the end of the first successful GET/POST. Default is FIRST_GET_POST")
            .create('c'));

    servletOptions.addOption(OptionBuilder.withLongOpt("servlet-exec-properties").hasArg().withArgName("file")
            .withDescription(
                    "The name of the file that stores the persistent servlet execution properties like initialization count. The default is "
                            + DEFAULT_EXEC_PROPS_FILE_NAME + ".")
            .create('x'));

    servletOptions.addOption(OptionBuilder.withLongOpt("listener-class").hasArg().withArgName("name")
            .withDescription(
                    "The name of a project lifecycle listener class to add to project after all other initialization has occurred. More than one may be provided.")
            .create('r'));

    servletOptions.addOption(OptionBuilder.withLongOpt("debug-options")
            .withDescription("Dump the option values to STDOUT.").create('g'));

    servletOptions.addOption(OptionBuilder.withLongOpt("default-data-source").hasArg().withArgName("id")
            .withDescription("The identifier of the default data source.").create('d'));

    servletOptions.addOption(OptionBuilder.withLongOpt("connection-provider-name").hasArg().withArgName("id")
            .withDescription(
                    "The name of the connection provider in the project.xml that should be used for obtaining connections.")
            .create('D'));

    servletOptions.addOption(OptionBuilder.withLongOpt("page-cache-max-size").hasArg().withArgName("size")
            .withDescription("The maximum number of pages to cache (for pages that allow caching)")
            .create('X'));
}

From source file:eu.chocolatejar.eclipse.plugin.cleaner.Main.java

@SuppressWarnings("static-access")
private Option generateOption(String opt, String longOpt, boolean hasArg, String description) {
    return OptionBuilder.withLongOpt(longOpt).withDescription(description).hasArg(hasArg).isRequired(false)
            .withArgName(longOpt).create(opt);
}

From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java

/**
 * Creates and adds a vertical size option to a given {@link Options}
 * object.//from w  w w  . j  a  v a2 s  .  c  o  m
 * 
 * @param options
 *            The <code>Options</code> object to add to.
 */
private static void addYSizeOption(final Options options) {
    OptionBuilder.withLongOpt(HEIGHT_KEY_LONG);
    OptionBuilder.withDescription(HEIGHT_DESCR);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(SIZE_ARG_NAME);
    OptionBuilder.withType(int.class);

    final Option height = OptionBuilder.create(HEIGHT_KEY);
    options.addOption(height);
}

From source file:com.facebook.presto.accumulo.examples.TpcHBatchWriter.java

@Override
public Options getOptions() {
    Options opts = new Options();
    opts.addOption(OptionBuilder.withLongOpt("path").withDescription("Path to the TPC-H orders.tbl file")
            .hasArg().isRequired().create(ORDERS_OPT));
    return opts;/* w  w  w .jav  a 2  s .  co  m*/
}

From source file:edu.usc.scrc.PriorityPruner.CommandLineOptions.java

/**
 * Creates an Option-object with both a full and a shorthand version of its
 * name./*from www . ja  va  2 s  .c  o  m*/
 * 
 * @param numArgs
 *            number of arguments required for every argument entry
 * @param typeOfArg
 *            type of argument expected
 * @param longOpt
 *            full name of this option
 * @param desc
 *            description of this option
 * @param isReq
 *            specifies if this option is required or not
 * @param shortOpt
 *            shorthand name for this option
 * @return a static Option-object
 */
private static Option createOptionTwoNames(int numArgs, String typeOfArg, String longOpt, String desc,
        boolean isReq, String shortOpt) {

    OptionBuilder.hasArgs(numArgs);
    OptionBuilder.withArgName(typeOfArg);
    OptionBuilder.withLongOpt(longOpt);
    OptionBuilder.withDescription(desc);
    OptionBuilder.isRequired(isReq);
    return OptionBuilder.create(shortOpt);
}

From source file:com.rapplogic.aru.uploader.wifi.WifiSketchUploader.java

private void runFromCmdLine(String[] args) throws org.apache.commons.cli.ParseException, IOException {
    CliOptions cliOptions = getCliOptions();

    cliOptions.addOption(OptionBuilder.withLongOpt(host).hasArg().isRequired(true)
            .withDescription("Host ip address of wifi device. Required").create("x")); // single arg is optional

    cliOptions.addOption(OptionBuilder.withLongOpt(port).hasArg().isRequired(true).withType(Number.class)
            .withDescription("Port of wifi server. Required").create("p"));

    cliOptions.getDefaults().put(connectionTimeoutSecs, "10");

    cliOptions.addOption(OptionBuilder.withLongOpt(connectionTimeoutSecs).hasArg().isRequired(false)
            .withType(Number.class).withDescription("Connection timeout seconds").create("q")); // arbitrary -- running out of letters

    cliOptions.getDefaults().put(readTimeoutSecs, "10");

    cliOptions.addOption(OptionBuilder.withLongOpt(readTimeoutSecs).hasArg().isRequired(false)
            .withType(Number.class).withDescription("Connection read seconds").create("v"));

    cliOptions.build();/*from www . ja va  2  s .com*/

    CommandLine commandLine = cliOptions.parse(args);

    if (commandLine != null) {
        new WifiSketchUploader().flash(commandLine.getOptionValue(CliOptions.sketch),
                commandLine.getOptionValue(host), cliOptions.getIntegerOption(port),
                cliOptions.getIntegerOption(connectionTimeoutSecs),
                cliOptions.getIntegerOption(readTimeoutSecs), commandLine.hasOption(CliOptions.verboseArg),
                cliOptions.getIntegerOption(CliOptions.ackTimeoutMillisArg),
                cliOptions.getIntegerOption(CliOptions.arduinoTimeoutArg),
                cliOptions.getIntegerOption(CliOptions.retriesPerPacketArg),
                cliOptions.getIntegerOption(CliOptions.delayBetweenRetriesMillisArg));
    }
}

From source file:com.linkedin.databus.bootstrap.utils.BootstrapTableReader.java

@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
    CommandLineParser cliParser = new GnuParser();

    Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen")
            .create(HELP_OPT_CHAR);/* w ww .  j  av a  2s .  c  om*/

    Option sourcesOption = OptionBuilder.withLongOpt(QUERY_CONFIG_OPT_LONG_NAME).withDescription("Query Config")
            .hasArg().withArgName("property_file").create(QUERY_CONFIG_OPT_CHAR);

    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME)
            .withDescription("Bootstrap DB properties to use").hasArg().withArgName("property_file")
            .create(BOOTSTRAP_DB_PROP_OPT_CHAR);

    Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME)
            .withDescription("Log4j properties to use").hasArg().withArgName("property_file")
            .create(LOG4J_PROPS_OPT_CHAR);
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(sourcesOption);
    options.addOption(dbOption);
    options.addOption(log4jPropsOption);

    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        LOG.fatal("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
    }

    if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
    } else {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);

        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);

        LOG.info("Using default logging settings");
    }

    if (cmd.hasOption(HELP_OPT_CHAR)) {
        printCliHelp(options);
        System.exit(0);
    }

    if (!cmd.hasOption(QUERY_CONFIG_OPT_CHAR)) {
        throw new RuntimeException("Query Config is not provided; use --help for usage");
    }

    if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR)) {
        throw new RuntimeException("Bootstrap config is not provided; use --help for usage");
    }

    String propFile1 = cmd.getOptionValue(QUERY_CONFIG_OPT_CHAR);
    String propFile2 = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
    LOG.info("Loading bootstrap DB config from properties file " + propFile2);

    _sQueryConfigProps = new Properties();
    FileInputStream f1 = new FileInputStream(propFile1);
    try {
        _sQueryConfigProps.load(f1);
    } finally {
        f1.close();
    }

    _sBootstrapConfigProps = new Properties();
    FileInputStream f2 = new FileInputStream(propFile2);
    try {
        _sBootstrapConfigProps.load(f2);
    } finally {
        f2.close();
    }
}

From source file:createSod.java

private static Options getOptions() {
    Options options = new Options();
    options.addOption("v", "version", false, "Version");
    options.addOption(OptionBuilder.withLongOpt("privatekey").withDescription("Private Key Location").hasArg()
            .withArgName("path").create());

    options.addOption(OptionBuilder.withLongOpt("keypass").withDescription("Key Password").hasArg()
            .withArgName("string").create());

    options.addOption(OptionBuilder.withLongOpt("certificate").withDescription("Certificate").hasArg()
            .withArgName("path").create());

    options.addOption(OptionBuilder.withLongOpt("content").withDescription("SOD Content").hasArg()
            .withArgName("path").create());

    options.addOption(OptionBuilder.withLongOpt("out").withDescription("Destination file").hasArg()
            .withArgName("path").create());

    return options;
}