Search in sources :

Example 76 with Options

use of org.apache.commons.cli.Options 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 77 with Options

use of org.apache.commons.cli.Options 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 78 with Options

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

the class SoapCLI method getCommandLine.

/**
     * Parses the command line arguments. If -h,--help is specified, displays usage and returns null.
     * @param args the command line arguments
     * @return
     * @throws ParseException
     */
protected CommandLine getCommandLine(String[] args) throws ParseException {
    CommandLineParser clParser = new GnuParser();
    CommandLine cl = null;
    Options opts = getAllOptions();
    try {
        cl = clParser.parse(opts, args);
    } catch (ParseException e) {
        if (helpOptionSpecified(args)) {
            usage();
            return null;
        } else
            throw e;
    }
    if (cl.hasOption(O_H)) {
        boolean showHiddenOptions = cl.hasOption(O_HIDDEN);
        usage(null, showHiddenOptions);
        return null;
    }
    if (!mDisableTargetServerOption && cl.hasOption(O_S))
        setServer(cl.getOptionValue(O_S));
    return cl;
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 79 with Options

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

the class PlaybackUtil method usage.

private static void usage(String errmsg) {
    if (errmsg != null) {
        System.err.println(errmsg);
    }
    String usage = "zmplayredo <options>";
    Options opts = sOptions;
    PrintWriter pw = new PrintWriter(System.err, true);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, formatter.getWidth(), usage, null, opts, formatter.getLeftPadding(), formatter.getDescPadding(), null);
    pw.flush();
    String trailer = SoapCLI.getAllowedDatetimeFormatsHelp();
    if (trailer != null && trailer.length() > 0) {
        System.err.println();
        System.err.println(trailer);
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) PrintWriter(java.io.PrintWriter)

Example 80 with Options

use of org.apache.commons.cli.Options in project phoenix by apache.

the class RegexBulkLoadTool method getOptions.

@Override
protected Options getOptions() {
    Options options = super.getOptions();
    options.addOption(REGEX_OPT);
    options.addOption(ARRAY_DELIMITER_OPT);
    return options;
}
Also used : Options(org.apache.commons.cli.Options)

Aggregations

Options (org.apache.commons.cli.Options)1086 CommandLine (org.apache.commons.cli.CommandLine)557 CommandLineParser (org.apache.commons.cli.CommandLineParser)382 ParseException (org.apache.commons.cli.ParseException)341 Option (org.apache.commons.cli.Option)325 HelpFormatter (org.apache.commons.cli.HelpFormatter)275 GnuParser (org.apache.commons.cli.GnuParser)207 DefaultParser (org.apache.commons.cli.DefaultParser)166 Test (org.junit.Test)148 PosixParser (org.apache.commons.cli.PosixParser)135 IOException (java.io.IOException)118 File (java.io.File)97 OptionGroup (org.apache.commons.cli.OptionGroup)56 DMLScript (org.apache.sysml.api.DMLScript)56 Path (org.apache.hadoop.fs.Path)54 ArrayList (java.util.ArrayList)38 BasicParser (org.apache.commons.cli.BasicParser)36 Properties (java.util.Properties)33 Configuration (org.apache.hadoop.conf.Configuration)31 FileInputStream (java.io.FileInputStream)29