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

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

Introduction

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

Prototype

String description

To view the source code for org.apache.commons.cli Option description.

Click Source Link

Document

description of the option

Usage

From source file:com.inetpsa.seed.plugin.CmdMojoDelegate.java

protected Command createCommand(CommandRegistry commandRegistry, String qualifiedName, String[] args) {
    if (Strings.isNullOrEmpty(qualifiedName)) {
        throw new IllegalArgumentException("No command named " + qualifiedName);
    }/*from w w  w  .j  a  v  a2 s . c om*/

    String commandScope;
    String commandName;

    if (qualifiedName.contains(":")) {
        String[] splitName = qualifiedName.split(":");
        commandScope = splitName[0].trim();
        commandName = splitName[1].trim();
    } else {
        commandScope = null;
        commandName = qualifiedName.trim();
    }

    // Build CLI options
    Options options = new Options();
    for (org.seedstack.seed.core.spi.command.Option option : commandRegistry.getOptionsInfo(commandScope,
            commandName)) {
        options.addOption(option.name(), option.longName(), option.hasArgument(), option.description());
    }

    // Parse the command options
    CommandLine cmd;
    try {
        cmd = commandLineParser.parse(options, args);
    } catch (ParseException e) {
        throw new IllegalArgumentException("Syntax error in arguments", e);
    }

    Map<String, String> optionValues = new HashMap<String, String>();
    for (Option option : cmd.getOptions()) {
        optionValues.put(option.getOpt(), option.getValue());
    }

    return commandRegistry.createCommand(commandScope, commandName, cmd.getArgList(), optionValues);
}

From source file:org.apache.batchee.cli.BatchEECLI.java

private static Options buildOptions(final Class<? extends Runnable> cmd, Map<String, Field> fields) {
    final Options options = new Options();
    Class<?> it = cmd;/*ww  w  . j a v  a2  s.  c o m*/
    while (it != null) {
        for (final Field f : it.getDeclaredFields()) {
            final org.apache.batchee.cli.command.api.Option option = f
                    .getAnnotation(org.apache.batchee.cli.command.api.Option.class);
            final org.apache.batchee.cli.command.api.Arguments arguments = f
                    .getAnnotation(org.apache.batchee.cli.command.api.Arguments.class);
            if (option != null && arguments != null) {
                throw new IllegalArgumentException("An @Option can't get @Arguments: " + f);
            }

            if (option != null) {
                final String name = option.name();
                final Option.Builder builder = Option.builder(name).desc(option.description()).hasArg();
                if (option.required()) {
                    builder.required();
                }
                options.addOption(builder.build());
                fields.put(name, f);
                f.setAccessible(true);
            } else if (arguments != null) {
                if (fields.put("", f) != null) {
                    throw new IllegalArgumentException("A command can only have a single @Arguments");
                }
                f.setAccessible(true);
            }
        }
        it = it.getSuperclass();
    }
    return options;
}

From source file:org.seedstack.seed.shell.internal.AbstractShell.java

@SuppressWarnings("unchecked")
protected Command createCommandAction(String qualifiedName, List<String> args) {
    if (Strings.isNullOrEmpty(qualifiedName)) {
        throw SeedException.createNew(ShellErrorCode.MISSING_COMMAND);
    }/*from w w  w. java  2 s  .  c  o  m*/

    String commandScope;
    String commandName;

    if (qualifiedName.contains(":")) {
        String[] splitName = qualifiedName.split(":");
        commandScope = splitName[0].trim();
        commandName = splitName[1].trim();
    } else {
        commandScope = null;
        commandName = qualifiedName.trim();
    }

    // Build CLI options
    Options options = new Options();
    for (org.seedstack.seed.core.spi.command.Option option : commandRegistry.getOptionsInfo(commandScope,
            commandName)) {
        options.addOption(option.name(), option.longName(), option.hasArgument(), option.description());
    }

    // Parse the command options
    CommandLine cmd;
    try {
        cmd = commandLineParser.parse(options, args.toArray(new String[args.size()]));
    } catch (ParseException e) {
        throw SeedException.wrap(e, ShellErrorCode.OPTIONS_SYNTAX_ERROR);
    }

    Map<String, String> optionValues = new HashMap<String, String>();
    for (Option option : cmd.getOptions()) {
        optionValues.put(option.getOpt(), option.getValue());
    }

    return commandRegistry.createCommand(commandScope, commandName, cmd.getArgList(), optionValues);
}

From source file:org.seedstack.shell.internal.AbstractShell.java

@SuppressWarnings("unchecked")
Command createCommandAction(String qualifiedName, List<String> args) {
    if (Strings.isNullOrEmpty(qualifiedName)) {
        throw SeedException.createNew(ShellErrorCode.MISSING_COMMAND);
    }//from ww w . ja  va 2 s . c  o m

    String commandScope;
    String commandName;

    if (qualifiedName.contains(":")) {
        String[] splitName = qualifiedName.split(":");
        commandScope = splitName[0].trim();
        commandName = splitName[1].trim();
    } else {
        commandScope = null;
        commandName = qualifiedName.trim();
    }

    // Build CLI options
    Options options = new Options();
    for (org.seedstack.seed.command.Option option : commandRegistry.getOptionsInfo(commandScope, commandName)) {
        options.addOption(option.name(), option.longName(), option.hasArgument(), option.description());
    }

    // Parse the command options
    CommandLine cmd;
    try {
        cmd = commandLineParser.parse(options, args.toArray(new String[args.size()]));
    } catch (ParseException e) {
        throw SeedException.wrap(e, ShellErrorCode.OPTIONS_SYNTAX_ERROR);
    }

    Map<String, String> optionValues = new HashMap<>();
    for (Option option : cmd.getOptions()) {
        optionValues.put(option.getOpt(), option.getValue());
    }

    return commandRegistry.createCommand(commandScope, commandName, cmd.getArgList(), optionValues);
}

From source file:org.zend.sdkcli.internal.options.DetectOptionUtility.java

private static void addBoolean(Options options, Method method) {
    final Option a = method.getAnnotation(Option.class);

    // create option object
    final org.apache.commons.cli.Option o = new org.apache.commons.cli.Option(a.opt(), a.description());
    if (a.longOpt() != null && a.longOpt().length() > 0) {
        o.setLongOpt(a.longOpt());//from ww w  .  j  a  v  a 2  s  .c o  m
    }
    o.setArgs(0);
    o.setRequired(a.required());

    // assign to options list options.addOption(o);
    options.addOption(o);
}

From source file:org.zend.sdkcli.internal.options.DetectOptionUtility.java

private static void addString(Options options, Method method) {
    final Option a = method.getAnnotation(Option.class);

    // create option object
    final org.apache.commons.cli.Option o = new org.apache.commons.cli.Option(a.opt(), a.description());
    if (a.longOpt() != null && a.longOpt().length() > 0) {
        o.setLongOpt(a.longOpt());//www  .j a  v a2s  . com
    }
    o.setArgs(a.numberOfArgs());
    o.setRequired(a.required());
    o.setType(a.type());
    o.setArgName(a.argName());

    // assign to options list
    options.addOption(o);
}