Example usage for org.apache.commons.cli Option getLongOpt

List of usage examples for org.apache.commons.cli Option getLongOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli Option getLongOpt.

Prototype

public String getLongOpt() 

Source Link

Document

Retrieve the long name of this Option.

Usage

From source file:be.dnsbelgium.rdap.client.ManGenerator.java

private static String getOptionString(Option option) {
    return String.format("%s%s%s", option.getOpt() == null ? "" : "-" + option.getOpt() + " ",
            option.getLongOpt() == null ? "" : "--" + option.getLongOpt() + " ",
            option.hasArg() ? "<" + option.getArgName() + ">" : ""

    ).trim();// w  w w  .j a v  a  2s.c  om
}

From source file:hivemall.optimizer.OptimizerOptions.java

public static void processOptions(@Nullable CommandLine cl, @Nonnull Map<String, String> options) {
    if (cl == null) {
        return;//w w  w  . jav  a 2s  . co  m
    }
    for (Option opt : cl.getOptions()) {
        String optName = opt.getLongOpt();
        if (optName == null) {
            optName = opt.getOpt();
        }
        options.put(optName, opt.getValue());
    }
}

From source file:com.ztesoft.zsmart.remoting.util.ServerUtil.java

/**
 * Description:commandLine -> properties <br>
 * //w ww. j a v  a  2s. c  o m
 * @author wang.jun<br>
 * @taskId <br>
 * @param commandLine
 * @return <br>
 */
public static Properties commandLine2Properties(final CommandLine commandLine) {
    Properties properties = new Properties();
    Option[] opts = commandLine.getOptions();

    if (opts != null) {
        for (Option opt : opts) {
            String name = opt.getLongOpt();
            String value = commandLine.getOptionValue(name);
            if (value != null) {
                properties.setProperty(name, value);
            }
        }
    }
    return properties;
}

From source file:com.teradata.benchto.driver.DriverApp.java

private static void exposeArgumentsAsPropertiesForSpring(CommandLine commandLine) {
    for (Option option : commandLine.getOptions()) {
        System.setProperty(option.getLongOpt(), option.getValue());
    }//from ww  w .j a  va  2s  .c  o m
}

From source file:maps.OptionsHandler.java

static private void printHelpOption() {
    System.out.println("Usage:");
    for (Option o : options.getOptions())
        System.out.println(String.format("\t-%s --%s\t%s", o.getOpt(), o.getLongOpt(), o.getDescription()));
    System.exit(0);//from   w w w.  j  av  a2  s  . c o  m
}

From source file:de.unirostock.sems.caro.CaRo.java

/**
 * USAGE./*from w w  w  .  j av  a2 s .c  o  m*/
 * 
 * @param options
 *          the options
 * @param err
 *          the error message
 */
public static void help(Options options, String err) {
    if (err != null && err.length() > 0)
        System.err.println(err);
    System.out.println("this is CaRo version " + CARO_VERSION);
    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(new Comparator<Option>() {

        private static final String OPTS_ORDER = "hcrio";

        public int compare(Option o1, Option o2) {
            return OPTS_ORDER.indexOf(o1.getLongOpt()) - OPTS_ORDER.indexOf(o2.getLongOpt());
        }
    });
    formatter.printHelp("java -jar CaRo.jar", options, true);
    if (DIE)
        System.exit(1);
}

From source file:com.datastax.brisk.demo.pricer.Pricer.java

/**
 * Printing out help message//from   www  .j a  v  a2  s. c om
 */
public static void printHelpMessage() {
    System.out.println("Usage: ./bin/pricer [options]\n\nOptions:");

    for (Object o : Session.availableOptions.getOptions()) {
        Option option = (Option) o;
        String upperCaseName = option.getLongOpt().toUpperCase();
        System.out.println(String.format("-%s%s, --%s%s%n\t\t%s%n", option.getOpt(),
                (option.hasArg()) ? " " + upperCaseName : "", option.getLongOpt(),
                (option.hasArg()) ? "=" + upperCaseName : "", option.getDescription()));
    }
}

From source file:by.stub.cli.CommandLineInterpreter.java

/**
 * Identifies what command line arguments that have been passed by user are matching available options
 *
 * @return a map of passed command line arguments where key is the name of the argument
 *///from  w w  w  .j a  v a  2s  .  com
public static Map<String, String> getCommandlineParams() {

    final Option[] options = line.getOptions();

    return new HashMap<String, String>() {
        {
            for (final Option option : options) {
                put(option.getLongOpt(), option.getValue());
            }
        }
    };
}

From source file:com.zimbra.common.util.CliUtil.java

/**
 * Looks up an <tt>Option</tt> by its short or long name.  This workaround is necessary
 * because <tt>CommandLine.hasOption()</tt> doesn't support long option names.
 *///ww  w . j  a  va2s . c o m
public static Option getOption(CommandLine cl, String name) {
    for (Option opt : cl.getOptions()) {
        if (StringUtil.equal(opt.getOpt(), name) || StringUtil.equal(opt.getLongOpt(), name)) {
            return opt;
        }
    }
    return null;
}

From source file:de.haber.xmind2latex.cli.CliParameters.java

/**
 * Helper method that throws a {@link ParseException} if parameter arguments are missing.
 * /*from   www.  j a va2s . c  om*/
 * @param cmd the concrete {@link CommandLine}
 * @param param name of the parameter that is to be validated
 * @param opts configured {@link Options}
 * @throws ParseException if the number of arguments does not correspond to the expected number of arguments for the given parameter
 */
public static void validateNumberOfArguments(CommandLine cmd, char param, Options opts) throws ParseException {
    Integer numberOfArgs = param2arguments.get(param);
    String[] tmp = cmd.getOptionValues(param);
    if (numberOfArgs != null && tmp != null && tmp.length % numberOfArgs != 0) {
        Option o = opts.getOption(Character.toString(param));
        String name = o.getLongOpt() != null ? o.getLongOpt() : Character.toString(param);
        throw new ParseException("Invalid amount of arguments for parameter " + name + ": <" + o.getArgName()
                + ">. Description: " + o.getDescription());
    }
}