Search in sources :

Example 96 with HelpFormatter

use of org.apache.commons.cli.HelpFormatter in project alluxio by Alluxio.

the class AlluxioFuse method parseOptions.

/**
   * Parses CLI options.
   *
   * @param args CLI args
   * @return Alluxio-FUSE configuration options
   */
private static AlluxioFuseOptions parseOptions(String[] args) {
    final Options opts = new Options();
    final Option mntPoint = Option.builder("m").hasArg().required(false).longOpt("mount-point").desc("Desired local mount point for alluxio-fuse.").build();
    final Option alluxioRoot = Option.builder("r").hasArg().required(false).longOpt("alluxio-root").desc("Path within alluxio that will be used as the root of the FUSE mount " + "(e.g., /users/foo; defaults to /)").build();
    final Option help = Option.builder("h").required(false).desc("Print this help").build();
    final Option fuseOption = Option.builder("o").valueSeparator(',').required(false).hasArgs().desc("FUSE mount options").build();
    opts.addOption(mntPoint);
    opts.addOption(alluxioRoot);
    opts.addOption(help);
    opts.addOption(fuseOption);
    final CommandLineParser parser = new DefaultParser();
    try {
        CommandLine cli = parser.parse(opts, args);
        if (cli.hasOption("h")) {
            final HelpFormatter fmt = new HelpFormatter();
            fmt.printHelp(AlluxioFuse.class.getName(), opts);
            return null;
        }
        String mntPointValue = cli.getOptionValue("m");
        String alluxioRootValue = cli.getOptionValue("r");
        List<String> fuseOpts = new ArrayList<>();
        boolean noUserMaxWrite = true;
        if (cli.hasOption("o")) {
            String[] fopts = cli.getOptionValues("o");
            // keep the -o
            for (final String fopt : fopts) {
                fuseOpts.add("-o" + fopt);
                if (noUserMaxWrite && fopt.startsWith("max_write")) {
                    noUserMaxWrite = false;
                }
            }
        }
        // from conf
        if (noUserMaxWrite) {
            final long maxWrite = Configuration.getLong(PropertyKey.FUSE_MAXWRITE_BYTES);
            fuseOpts.add(String.format("-omax_write=%d", maxWrite));
        }
        if (mntPointValue == null) {
            mntPointValue = Configuration.get(PropertyKey.FUSE_MOUNT_DEFAULT);
            LOG.info("Mounting on default {}", mntPointValue);
        }
        if (alluxioRootValue == null) {
            alluxioRootValue = Configuration.get(PropertyKey.FUSE_FS_ROOT);
            LOG.info("Using default alluxio root {}", alluxioRootValue);
        }
        final boolean fuseDebug = Configuration.getBoolean(PropertyKey.FUSE_DEBUG_ENABLED);
        return new AlluxioFuseOptions(mntPointValue, alluxioRootValue, fuseDebug, fuseOpts);
    } catch (ParseException e) {
        System.err.println("Error while parsing CLI: " + e.getMessage());
        final HelpFormatter fmt = new HelpFormatter();
        fmt.printHelp(AlluxioFuse.class.getName(), opts);
        return null;
    }
}
Also used : Options(org.apache.commons.cli.Options) ArrayList(java.util.ArrayList) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 97 with HelpFormatter

use of org.apache.commons.cli.HelpFormatter in project alluxio by Alluxio.

the class GetConf method printHelp.

/**
   * Prints the help message.
   *
   * @param message message before standard usage information
   */
public static void printHelp(String message) {
    System.err.println(message);
    HelpFormatter help = new HelpFormatter();
    help.printHelp(USAGE, OPTIONS);
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter)

Example 98 with HelpFormatter

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

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

the class SmtpClient method usage.

private void usage() {
    HelpFormatter help = new HelpFormatter();
    help.setWidth(100);
    help.printHelp("zmjava " + getClass().getName() + " [OPTIONS] [HOSTNAME]", options);
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter)

Example 100 with HelpFormatter

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

the class ProxyConfUtil method usage.

private static void usage(String errmsg) {
    if (errmsg != null) {
        System.out.println(errmsg);
    }
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("ProxyConfGen [options] ", "where [options] are one of:", mOptions, "ProxyConfGen generates the NGINX Proxy configuration files");
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter)

Aggregations

HelpFormatter (org.apache.commons.cli.HelpFormatter)273 Options (org.apache.commons.cli.Options)136 CommandLine (org.apache.commons.cli.CommandLine)126 CommandLineParser (org.apache.commons.cli.CommandLineParser)110 ParseException (org.apache.commons.cli.ParseException)103 GnuParser (org.apache.commons.cli.GnuParser)92 Path (org.apache.hadoop.fs.Path)42 PrintWriter (java.io.PrintWriter)35 Option (org.apache.commons.cli.Option)29 Job (org.apache.hadoop.mapreduce.Job)27 Configuration (org.apache.hadoop.conf.Configuration)21 File (java.io.File)17 IOException (java.io.IOException)14 DefaultParser (org.apache.commons.cli.DefaultParser)13 PosixParser (org.apache.commons.cli.PosixParser)12 FileSystem (org.apache.hadoop.fs.FileSystem)12 BasicParser (org.apache.commons.cli.BasicParser)11 ArrayList (java.util.ArrayList)8 URI (java.net.URI)6 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)6