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:nl.systemsgenetics.eqtlinteractionanalyser.eqtlinteractionanalyser.createOptionsListForManual.java

/**
 * @param args the command line arguments
 *//*from   w  w w. j av  a  2 s . c  om*/
public static void main(String[] args) {

    Options options = EQTLInteractionAnalyser.OPTIONS;

    System.out.println("| Short | Long | Description |");
    System.out.println("|-------|------|-------------|");

    for (Object optionO : options.getOptions()) {
        Option option = (Option) optionO;
        System.out.print("| -");
        System.out.print(option.getOpt());
        System.out.print(" | --");
        System.out.print(option.getLongOpt());
        System.out.print(" | ");
        System.out.print(option.getDescription());
        System.out.println(" | ");
    }

}

From source file:nl.toolforge.karma.console.CommandRenderer.java

private static StringBuffer printCommand(CommandDescriptor descriptor, Option[] options, boolean showOptions,
        boolean showHelp) {

    StringBuffer buffer = new StringBuffer();
    String commandNameAlias = descriptor.getName() + " (" + descriptor.getAlias() + ")";

    buffer.append(commandNameAlias).append(StringUtils.repeat(" ", COMMAND_FILL - commandNameAlias.length()));
    if (!showOptions) {
        buffer.append(descriptor.getDescription());
    }//from  www .  j av a2  s.  com
    buffer.append("\n");

    if (showOptions) {
        for (int j = 0; j < options.length; j++) {

            Option o = options[j];

            String leftPadding = "   ";

            buffer.append(leftPadding).append("-" + o.getOpt()).append(", --" + o.getLongOpt());

            String args = "";
            if (o.hasArg()) {
                args = " <".concat(o.getArgName()).concat(">");
            }

            // todo when the commands are described with too much of text, then FILL will run out of count ...
            //
            buffer.append(args.concat(StringUtils.repeat(" ", OPTION_FILL - (o.getLongOpt() + args).length())));
            buffer.append(leftPadding);
            if (!o.isRequired()) {
                buffer.append("(Optional) ");
            }
            buffer.append(o.getDescription());
            buffer.append("\n");
        }
    }

    if (showHelp) {
        buffer.append("\n");

        String trimmed = NiftyStringUtils.deleteWhiteSpaceExceptOne(descriptor.getHelp());
        String[] split = NiftyStringUtils.split(trimmed, " ", 120);
        String joined = StringUtils.join(split, "\n");

        buffer.append(joined);
        buffer.append("\n");
    }

    return buffer;
}

From source file:openlr.otk.options.InputFileOrStdInOption.java

/**
 * Instantiates a new input file option.
 *//*from w  w  w  . j  a  v a 2s  . c o  m*/
public InputFileOrStdInOption() {
    super("i", "input-file", true,
            "The path to the input file, if this option is missing the tool awaits input from standard input",
            false);
    Option option = getOption();
    delegatedPureFileOption = new InputFileOption(option.getOpt(), option.getLongOpt(), option.getDescription(),
            false);
}

From source file:openlr.otk.options.OutputFileOrStdOutOption.java

/**
 * Instantiates a new output file option.
 * @param failIfFileAlreadyExists//from ww w  .  j  ava2s  .c  om
 *            A flag that determines whether this option processor should
 *            fail during {@link #parse(String, Object...)} if the specified
 *            target file already exists.
 */
public OutputFileOrStdOutOption(final boolean failIfFileAlreadyExists) {
    super("o", "output-file", true,
            "path to the the output file [if missing output is written to standard out]", false);
    Option option = getOption();
    delegatedPureFileOption = new FileOption(option.getOpt(), option.getLongOpt(), option.getDescription(),
            false, failIfFileAlreadyExists);
}

From source file:org.apache.accumulo.core.util.shell.commands.SetShellIterCommand.java

@Override
public Options getOptions() {
    // Remove the options that specify which type of iterator this is, since
    // they are all scan iterators with this command.
    final HashSet<OptionGroup> groups = new HashSet<OptionGroup>();
    final Options parentOptions = super.getOptions();
    final Options modifiedOptions = new Options();
    for (Iterator<?> it = parentOptions.getOptions().iterator(); it.hasNext();) {
        Option o = (Option) it.next();
        if (!IteratorScope.majc.name().equals(o.getOpt()) && !IteratorScope.minc.name().equals(o.getOpt())
                && !IteratorScope.scan.name().equals(o.getOpt()) && !"table".equals(o.getLongOpt())) {
            modifiedOptions.addOption(o);
            OptionGroup group = parentOptions.getOptionGroup(o);
            if (group != null)
                groups.add(group);/*from   w  w  w . j av  a 2s  .  c om*/
        }
    }
    for (OptionGroup group : groups) {
        modifiedOptions.addOptionGroup(group);
    }

    profileOpt = new Option("pn", "profile", true, "iterator profile name");
    profileOpt.setRequired(true);
    profileOpt.setArgName("profile");

    modifiedOptions.addOption(profileOpt);

    return modifiedOptions;
}

From source file:org.apache.accumulo.shell.commands.CompactCommand.java

private void put(CommandLine cl, Map<String, String> opts, Option opt, CompactionSettings setting) {
    if (cl.hasOption(opt.getLongOpt()))
        setting.put(opts, cl.getOptionValue(opt.getLongOpt()));
}

From source file:org.apache.accumulo.shell.ShellUtil.java

public static Map<String, String> parseMapOpt(CommandLine cl, Option opt) {
    if (cl.hasOption(opt.getLongOpt())) {
        Builder<String, String> builder = ImmutableMap.builder();
        String[] keyVals = cl.getOptionValue(opt.getLongOpt()).split(",");
        for (String keyVal : keyVals) {
            String[] sa = keyVal.split("=");
            builder.put(sa[0], sa[1]);//www.ja  va  2  s. co  m
        }

        return builder.build();
    } else {
        return Collections.emptyMap();
    }

}

From source file:org.apache.activemq.apollo.util.cli.CommonsCLISupport.java

/**
 *///  w  w  w  . j  a  va  2s  .  c om
static public String[] setOptions(Object target, CommandLine cli) {
    Option[] options = cli.getOptions();
    for (Option option : options) {
        String name = option.getLongOpt();
        if (name == null)
            continue;

        String propName = convertOptionToPropertyName(name);

        String value = option.getValue();
        if (value != null) {
            Class<?> type = IntrospectionSupport.getPropertyType(target, propName);
            if (type.isArray()) {
                IntrospectionSupport.setProperty(target, propName, option.getValues());
            } else if (type.isAssignableFrom(ArrayList.class)) {
                IntrospectionSupport.setProperty(target, propName, new ArrayList(option.getValuesList()));
            } else if (type.isAssignableFrom(HashSet.class)) {
                IntrospectionSupport.setProperty(target, propName, new HashSet(option.getValuesList()));
            } else {
                IntrospectionSupport.setProperty(target, propName, value);
            }
        } else {
            IntrospectionSupport.setProperty(target, propName, true);
        }
    }
    return cli.getArgs();
}

From source file:org.apache.ambari.servicemonitor.utils.OptionHelper.java

public static String buildParsedOptionList(CommandLine commandLine) {

    StringBuilder builder = new StringBuilder();
    for (Option option : commandLine.getOptions()) {
        builder.append(option.getOpt());
        if (option.getLongOpt() != null) {
            builder.append("/").append(option.getLongOpt());
        }/*from ww  w  .  j  av a 2  s  . co  m*/
        builder.append(": ");
        List valuesList = option.getValuesList();
        builder.append("[");
        int count = 0;
        for (Object elt : valuesList) {
            if (count > 0) {
                builder.append(", ");
            }
            builder.append('"').append(elt.toString()).append("\"");
        }
        builder.append("]\n");
    }
    return builder.toString();
}

From source file:org.apache.cassandra.contrib.stress.Stress.java

/**
 * Printing out help message/*from ww w  .j a v  a2s  .  c  o m*/
 */
public static void printHelpMessage() {
    System.out.println("Usage: ./bin/stress [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()));
    }
}