Search in sources :

Example 56 with Option

use of org.apache.commons.cli.Option in project hbase by apache.

the class AbstractHBaseTool method addRequiredOptWithArg.

protected void addRequiredOptWithArg(String shortOpt, String longOpt, String description) {
    Option option = new Option(shortOpt, longOpt, true, description);
    option.setRequired(true);
    addOption(option);
}
Also used : Option(org.apache.commons.cli.Option)

Example 57 with Option

use of org.apache.commons.cli.Option in project zm-mailbox by Zimbra.

the class LocalConfigCLI method usage.

/**
     * Prints supported usage to stdout. Removes hidden options from the list to be printed
     *
     */
private void usage() {
    Collection<Object> options = mOptions.getOptions();
    Options displayOptions = new Options();
    for (Object obj : options) {
        // copy over the supported options
        // should be a safe cast, this api REALLY needs generics
        Option opt = (Option) obj;
        if (!"all".equals(opt.getLongOpt())) {
            displayOptions.addOption(opt);
        }
    }
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("zmlocalconfig [options] [args]", "where [options] are:", displayOptions, "");
    System.exit(0);
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) Option(org.apache.commons.cli.Option)

Example 58 with Option

use of org.apache.commons.cli.Option in project zm-mailbox by Zimbra.

the class SoapCLI method getAllOptions.

/**
     * Returns an <tt>Options</tt> object that combines the standard options
     * and the hidden ones.
     */
@SuppressWarnings("unchecked")
private Options getAllOptions() {
    Options newOptions = new Options();
    Set<OptionGroup> groups = new HashSet<OptionGroup>();
    Options[] optionses = new Options[] { mOptions, mHiddenOptions };
    for (Options options : optionses) {
        for (Option opt : (Collection<Option>) options.getOptions()) {
            OptionGroup group = options.getOptionGroup(opt);
            if (group != null) {
                groups.add(group);
            } else {
                newOptions.addOption(opt);
            }
        }
    }
    for (OptionGroup group : groups) {
        newOptions.addOptionGroup(group);
    }
    return newOptions;
}
Also used : Options(org.apache.commons.cli.Options) OptionGroup(org.apache.commons.cli.OptionGroup) Collection(java.util.Collection) Option(org.apache.commons.cli.Option) HashSet(java.util.HashSet)

Example 59 with Option

use of org.apache.commons.cli.Option in project zm-mailbox by Zimbra.

the class FixCalendarPriorityUtil method setupCommandLineOptions.

protected void setupCommandLineOptions() {
    super.setupCommandLineOptions();
    Options options = getOptions();
    Option accountOpt = new Option(O_ACCOUNT, "account", true, "account email addresses seperated by white space or \"all\" for all accounts");
    accountOpt.setArgs(Option.UNLIMITED_VALUES);
    options.addOption(accountOpt);
    options.addOption(new Option(null, O_SYNC, false, "run synchronously; default is asynchronous"));
    options.addOption(SoapCLI.OPT_AUTHTOKEN);
    options.addOption(SoapCLI.OPT_AUTHTOKENFILE);
}
Also used : Options(org.apache.commons.cli.Options) Option(org.apache.commons.cli.Option)

Example 60 with Option

use of org.apache.commons.cli.Option in project zm-mailbox by Zimbra.

the class VolumeCLI method printOpt.

private void printOpt(String optStr, int leftPad) {
    Options options = getOptions();
    Option opt = options.getOption(optStr);
    StringBuilder buf = new StringBuilder();
    buf.append(Strings.repeat(" ", leftPad));
    buf.append('-').append(opt.getOpt()).append(",--").append(opt.getLongOpt());
    if (opt.hasArg()) {
        buf.append(" <arg>");
    }
    buf.append(Strings.repeat(" ", 35 - buf.length()));
    buf.append(opt.getDescription());
    System.err.println(buf.toString());
}
Also used : Options(org.apache.commons.cli.Options) Option(org.apache.commons.cli.Option)

Aggregations

Option (org.apache.commons.cli.Option)152 Options (org.apache.commons.cli.Options)105 CommandLine (org.apache.commons.cli.CommandLine)53 CommandLineParser (org.apache.commons.cli.CommandLineParser)52 ParseException (org.apache.commons.cli.ParseException)41 GnuParser (org.apache.commons.cli.GnuParser)39 HelpFormatter (org.apache.commons.cli.HelpFormatter)30 File (java.io.File)13 OptionGroup (org.apache.commons.cli.OptionGroup)13 FileInputStream (java.io.FileInputStream)10 IOException (java.io.IOException)10 HashMap (java.util.HashMap)9 DefaultParser (org.apache.commons.cli.DefaultParser)9 Properties (java.util.Properties)8 BasicParser (org.apache.commons.cli.BasicParser)6 ConsoleAppender (org.apache.log4j.ConsoleAppender)6 PatternLayout (org.apache.log4j.PatternLayout)6 ArrayList (java.util.ArrayList)5 PosixParser (org.apache.commons.cli.PosixParser)5 List (java.util.List)3