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.github.artifactresolver.MavenDependencyDownloader.java

/**
 * Set up CLI options./*from  w w  w.  j  a  v a  2s .  com*/
 */
@SuppressWarnings("static-access")
private void createOptions() {
    options = new Options();

    Option help = new Option("h", "help", false, "print this usage and exit");

    Option jsonFile = OptionBuilder.withLongOpt("dependency-file")
            .withDescription("use this JSON dependency file (default:" + DEFAULT_DEPENDENCY_FILE + ")").hasArg()
            .withArgName("JSON-File").create('f');

    Option depDir = OptionBuilder.withLongOpt("dependency-dir")
            .withDescription(
                    "download dependencies to this folder (default:" + DEFAULT_LOCAL_DOWNLOAD_REPO + ")")
            .hasArg().withArgName("Directory").create('d');

    Option javadoc = OptionBuilder.withLongOpt("with-javadoc")
            .withDescription("download javadoc attachment of artifact").create('j');
    Option sources = OptionBuilder.withLongOpt("with-sources")
            .withDescription("download source attachment of artifact").create('s');

    options.addOption(help);
    options.addOption(depDir);
    options.addOption(jsonFile);
    options.addOption(javadoc);
    options.addOption(sources);
}

From source file:jo.jdk.jacoco_test.ReportGenerator.java

private static Option createOption(String arg, String longOpt, String description, String argName) {
    return OptionBuilder.withLongOpt(longOpt).withDescription(description).hasArg(true).withArgName(argName)
            .isRequired(true).create(arg);
}

From source file:com.zaradai.kunzite.trader.tools.EodDownloadOptionsParser.java

@Override
protected void addOptions(Options options) {
    options.addOption(OptionBuilder.withLongOpt(PROPERTY_OPTION).withArgName("key=value").hasArgs(2)
            .withValueSeparator().withDescription("Generic key value pair properties").create('p'));
    options.addOption(OptionBuilder.withLongOpt(TARGET_OPTION).withArgName("target folder").hasArgs(1)
            .withDescription("Target folder to contain encoded files for output types that "
                    + "store their data in folders such as CSV.  If specified the folder must exist")
            .create("t"));
    options.addOption(OptionBuilder.withLongOpt(TARGET_TYPE_OPTION).withArgName("type").hasArgs(1)
            .withDescription("Target output type, e.g. CSV, COMPACT, MONGO").create("o"));
    options.addOption(OptionBuilder.withLongOpt(SYMBOLS_OPTION).isRequired().withArgName("values")
            .withValueSeparator(' ').hasArgs(Option.UNLIMITED_VALUES)
            .withDescription("A list of space separated symbols to download data for, e.g. INTC AAPL F AMAT")
            .create("sm"));
    options.addOption(OptionBuilder.withLongOpt(THREADS_OPTION).withArgName("num threads").hasArgs(1)
            .withDescription("Specify number of conversion threads, default is 1").create("th"));
    options.addOption(OptionBuilder.withLongOpt(FROM_OPTION).isRequired().hasArgs(1).withArgName("date")
            .withDescription("Date to start the download from, format is YYYY-MM-dd, e.g. 2013-06-14")
            .create("f"));
    options.addOption(OptionBuilder.withLongOpt(UNTIL_OPTION).withArgName("date").hasArgs(1)
            .withDescription(//from  ww w .  j av a2  s .  c o m
                    "Date to end the download range, format is YYYY-MM-dd, e.g. 2013-06-14.  Default is"
                            + " today if not specified")
            .create("u"));
}

From source file:de.vandermeer.skb.commons.utils.CLIApache.java

@Override
public Com_Coin declareOptions(PropertyTable prop) {
    String optShort;/*from ww  w. j a  v  a2  s .co m*/
    String optLong;
    CC_Warning ret = null;

    for (String current : prop.keys()) {
        if (prop.hasPropertyValue(current, EAttributeKeys.CLI_PARAMETER_TYPE)) {
            Object o = Skb_ObjectUtils.CONVERT(prop.get(current, EAttributeKeys.CLI_PARAMETER_LONG),
                    Object.class, NONull.get, NONone.get);
            if (!(o instanceof Com_Coin)) {
                optLong = o.toString();
            } else {
                optLong = null;
            }
            OptionBuilder.withLongOpt(optLong);

            o = Skb_ObjectUtils.CONVERT(prop.get(current, EAttributeKeys.CLI_PARAMETER_DESCRIPTION_SHORT),
                    Object.class, NONull.get, NONone.get);
            OptionBuilder.withDescription(o.toString());

            o = Skb_ObjectUtils.CONVERT(prop.get(current, EAttributeKeys.CLI_PARAMETER_DESCRIPTION_ARGUMENTS),
                    Object.class, NONull.get, NONone.get);
            if (!(o instanceof Com_Coin) && o.toString().length() > 0) {
                OptionBuilder.hasArg();
                OptionBuilder.withArgName(o.toString());
            } else {
                OptionBuilder.hasArg(false);
            }

            switch (this.typeMap
                    .getPair4Source(prop.get(current, EAttributeKeys.CLI_PARAMETER_TYPE).toString())) {
            case JAVA_BOOLEAN:
                OptionBuilder.withType(Boolean.class);
                break;
            case JAVA_DOUBLE:
                OptionBuilder.withType(Double.class);
                break;
            case JAVA_INTEGER:
                OptionBuilder.withType(Integer.class);
                break;
            case JAVA_LONG:
                OptionBuilder.withType(Long.class);
                break;
            case JAVA_STRING:
            default:
                OptionBuilder.withType(String.class);
                break;
            }

            o = prop.get(current, EAttributeKeys.CLI_PARAMETER_SHORT);
            if (o != null && !(o instanceof Com_Coin)) {
                optShort = o.toString();
            } else {
                optShort = null;
            }

            if (optShort != null && optLong != null) {
                this.options.addOption(OptionBuilder.create(optShort.charAt(0)));
                this.optionList.put(current, optLong);
            } else if (optLong != null) {
                this.options.addOption(OptionBuilder.create());
                this.optionList.put(current, optLong);
            } else {
                //dummy create, nothing to be done since no option set (short/long)
                OptionBuilder.withLongOpt("__dummyLongOpt__");
                OptionBuilder.create();

                if (ret == null) {
                    ret = new CC_Warning();
                }
                ret.add(new Message5WH_Builder().addWhat("no short and no long options for <").addWhat(current)
                        .addWhat(">").build());
            }
        }
    }

    if (ret == null) {
        return NOSuccess.get;
    }
    return ret;
}

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

/**
 * Creates and adds a state size multiplier option to a given
 * {@link Options} object.//from w  w w.  j  ava2  s . c  om
 * 
 * @param options
 *            The <code>Options</code> object to add to.
 */
private static void addStateSizeMultiplierOption(final Options options) {
    OptionBuilder.withLongOpt(STATE_SIZE_MULTIPLIER_KEY_LONG);
    OptionBuilder.withDescription(STATE_SIZE_MULTIPLIER_DESCR);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(SIZE_ARG_NAME);
    OptionBuilder.withType(double.class);

    final Option stateSizeMultiplier = OptionBuilder.create(STATE_SIZE_MULTIPLIER_KEY);
    options.addOption(stateSizeMultiplier);
}

From source file:com.netspective.sparx.security.authenticator.SingleUserServletLoginAuthenticator.java

private Options createAuthenticatorOptions() {
    Options authenticatorOptions = new Options();
    authenticatorOptions.addOption(/*from   w  w w .ja  v a  2  s.c  om*/
            OptionBuilder.withLongOpt("help").withDescription("Print options to stdout").create('?'));
    authenticatorOptions.addOption(OptionBuilder.withLongOpt("user-id").hasArg().withArgName("id")
            .withDescription("The user id that should be used to log the user in").isRequired().create('u'));
    authenticatorOptions.addOption(OptionBuilder.withLongOpt("show-encrypted-password")
            .withDescription("Prints the encrypted version of plain-text password to stdout").create('s'));

    OptionGroup passwordOptionGroup = new OptionGroup();
    passwordOptionGroup.setRequired(true);
    passwordOptionGroup.addOption(OptionBuilder.withLongOpt("plain-text-password").hasArg()
            .withArgName("plain-text").withDescription("The plain-text password for the user").create('p'));
    passwordOptionGroup.addOption(OptionBuilder.withLongOpt("encrypted-password").hasArg()
            .withArgName("encrypted-text").withDescription("The encrypted password for the user").create('P'));

    authenticatorOptions.addOptionGroup(passwordOptionGroup);
    return authenticatorOptions;
}

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

@SuppressWarnings("static-access")
@Override//from  w  w  w .ja  v  a 2s.  co  m
public Options getOptions() {
    Options options = super.getOptions();

    options.addOption(OptionBuilder.withLongOpt("output").hasArg().withArgName("file").create('o'));
    options.addOption(OptionBuilder.withLongOpt("epsilon").hasArg().withArgName("e1,e2,...").create('e'));
    options.addOption(OptionBuilder.withLongOpt("diff").create('d'));

    return options;
}

From source file:com.linkedin.databus.bootstrap.utils.BootstrapAvroFileSeederMain.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);/*  www .  ja  v a  2 s .  com*/

    Option sourcesOption = OptionBuilder.withLongOpt(PHYSICAL_CONFIG_OPT_LONG_NAME)
            .withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file")
            .create(PHYSICAL_CONFIG_OPT_CHAR);

    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME)
            .withDescription("Bootstrap producer 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);
        Logger.getRootLogger().setLevel(Level.INFO); //using info as the default log level
        LOG.info("Using default logging settings. Log Level is :" + Logger.getRootLogger().getLevel());
    }

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

    if (!cmd.hasOption(PHYSICAL_CONFIG_OPT_CHAR))
        throw new RuntimeException("Sources 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");

    _sSourcesConfigFile = cmd.getOptionValue(PHYSICAL_CONFIG_OPT_CHAR);

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

    _sBootstrapConfigProps = new Properties();
    FileInputStream fis = new FileInputStream(propFile);
    try {
        _sBootstrapConfigProps.load(fis);
    } finally {
        fis.close();
    }
}

From source file:com.rapplogic.aru.uploader.nordic.NordicSketchUploader.java

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

    cliOptions.addOption(OptionBuilder.withLongOpt(serialPort).hasArg().isRequired(true).withDescription(
            "Serial port of of Arduino running NordicSPI2Serial sketch (e.g. /dev/tty.usbserial-A6005uRz). Required")
            .create("p"));

    cliOptions.addOption(OptionBuilder.withLongOpt(baudRate).hasArg().isRequired(true).withType(Number.class)
            .withDescription("Baud rate of Arduino. Required").create("b"));

    cliOptions.build();//from ww w .  jav a  2  s .c  o m

    CommandLine commandLine = cliOptions.parse(args);

    if (commandLine != null) {
        new NordicSketchUploader().flash(commandLine.getOptionValue(CliOptions.sketch),
                commandLine.getOptionValue(serialPort), cliOptions.getIntegerOption(baudRate),
                commandLine.hasOption(CliOptions.verboseArg),
                cliOptions.getIntegerOption(CliOptions.ackTimeoutMillisArg),
                cliOptions.getIntegerOption(CliOptions.arduinoTimeoutArg),
                cliOptions.getIntegerOption(CliOptions.retriesPerPacketArg),
                cliOptions.getIntegerOption(CliOptions.delayBetweenRetriesMillisArg));
    }
}

From source file:com.xiaoxiaomo.mr.utils.kafka.HadoopJob.java

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

    options.addOption(OptionBuilder.withArgName("topics").withLongOpt("topics").hasArg()
            .withDescription("kafka topics").create("t"));

    options.addOption(OptionBuilder.withArgName("groupid").withLongOpt("consumer-group").hasArg()
            .withDescription("kafka consumer groupid").create("g"));

    options.addOption(OptionBuilder.withArgName("zk").withLongOpt("zk-connect").hasArg()
            .withDescription("ZooKeeper connection String").create("z"));

    options.addOption(OptionBuilder.withArgName("offset").withLongOpt("offset-reset").hasArg()
            .withDescription("Reset all offsets to either 'earliest' or 'latest'").create("o"));

    options.addOption(OptionBuilder.withArgName("compression").withLongOpt("compress-output").hasArg()
            .withDescription("GZip output compression on|off").create("c"));

    options.addOption(OptionBuilder.withArgName("ip_address").withLongOpt("remote").hasArg()
            .withDescription("Running on a remote hadoop node").create("r"));

    options.addOption(OptionBuilder.withLongOpt("help").withDescription("Show this help").create("h"));

    return options;
}