Search in sources :

Example 96 with GnuParser

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

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

the class ProxyConfUtil method parseArgs.

private static CommandLine parseArgs(String[] args) {
    CommandLineParser parser = new GnuParser();
    CommandLine cl = null;
    try {
        cl = parser.parse(mOptions, args, false);
    } catch (ParseException pe) {
        usage(pe.getMessage());
        return cl;
    }
    return cl;
}
Also used : 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 98 with GnuParser

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

the class RedoLogVerify method parseArgs.

private static CommandLine parseArgs(String[] args) {
    CommandLineParser parser = new GnuParser();
    CommandLine cl = null;
    try {
        cl = parser.parse(sOptions, args);
    } catch (ParseException pe) {
        usage(pe.getMessage());
    }
    return cl;
}
Also used : 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 99 with GnuParser

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

the class MetadataDump method parseArgs.

private static CommandLine parseArgs(String[] args) {
    CommandLineParser parser = new GnuParser();
    CommandLine cl = null;
    try {
        cl = parser.parse(sOptions, args);
    } catch (ParseException pe) {
        usage(pe.getMessage());
        System.exit(1);
    }
    return cl;
}
Also used : 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 100 with GnuParser

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

the class TestLdapReadTimeout method main.

/**
     * /Users/pshao/dev/workspace/sandbox/sandbox/bin>/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java  LdapReadTimeout
     * /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java LdapReadTimeout
     * 
     * zmjava com.zimbra.qa.unittest.TestLdapReadTimeout -s 5
     * zmjava com.zimbra.qa.unittest.TestLdapReadTimeout -H ldap://localhost:389 -D uid=zimbra,cn=admins,cn=zimbra -w zimbra -s 5
     * 
     * @param args
     */
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(O_HELP, false, "print usage");
    options.addOption(O_SLEEP, true, "upon hitting an Exception, minutes to wait until exiting the program.  " + "If not specified, will exit immediately.");
    options.addOption(O_URI, true, "URI. e.g. ldap://localhost:389");
    options.addOption(O_BINDDN, true, "bind DN");
    options.addOption(O_PASSWORD, true, "password");
    CommandLine cl = null;
    try {
        CommandLineParser parser = new GnuParser();
        cl = parser.parse(options, args);
        if (cl == null) {
            throw new ParseException("");
        }
    } catch (ParseException e) {
        usage(options);
        e.printStackTrace();
        System.exit(1);
    }
    if (cl.hasOption(O_HELP)) {
        usage(options);
        System.exit(0);
    }
    String uri = null;
    String bindDN = null;
    String password = null;
    Integer minutesToWait = null;
    if (cl.hasOption(O_URI)) {
        uri = cl.getOptionValue(O_URI);
    } else {
        uri = "ldap://localhost:389";
    }
    if (cl.hasOption(O_BINDDN)) {
        bindDN = cl.getOptionValue(O_BINDDN);
    } else {
        bindDN = "uid=zimbra,cn=admins,cn=zimbra";
    }
    if (cl.hasOption(O_PASSWORD)) {
        password = cl.getOptionValue(O_PASSWORD);
    } else {
        password = "zimbra";
    }
    if (cl.hasOption(O_SLEEP)) {
        String wait = cl.getOptionValue(O_SLEEP);
        try {
            minutesToWait = Integer.valueOf(wait);
        } catch (NumberFormatException e) {
            usage(options);
            e.printStackTrace();
            System.exit(1);
        }
    }
    LdapReadTimeoutTester tester = null;
    try {
        // tester = new JNDITest(uri, bindDN, password);  // fails
        // works
        tester = new UnboundIDTest(uri, bindDN, password);
        System.out.println("=============");
        System.out.println(tester.getClass().getCanonicalName());
        System.out.println("LDAP server URI: " + uri);
        System.out.println("bind DN: " + bindDN);
        System.out.println("=============");
        System.out.println();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    long startTime = System.currentTimeMillis();
    test(tester);
    long endTime = System.currentTimeMillis();
    long elapsed = endTime - startTime;
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    System.out.println();
    System.out.println(tester.getClass().getCanonicalName());
    System.out.println("Started at: " + fmt.format(new Date(startTime)));
    System.out.println("Ended at: " + fmt.format(new Date(endTime)));
    System.out.println("Elapsed = " + (elapsed / 1000) + " seconds");
    System.out.println();
    if (minutesToWait != null) {
        System.out.println("Sleeping for " + minutesToWait + " minutes before exiting...");
        Thread.sleep(minutesToWait * 60 * 1000);
    }
}
Also used : Options(org.apache.commons.cli.Options) LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) GnuParser(org.apache.commons.cli.GnuParser) ParseException(org.apache.commons.cli.ParseException) Date(java.util.Date) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

GnuParser (org.apache.commons.cli.GnuParser)208 CommandLine (org.apache.commons.cli.CommandLine)187 Options (org.apache.commons.cli.Options)165 CommandLineParser (org.apache.commons.cli.CommandLineParser)158 ParseException (org.apache.commons.cli.ParseException)139 HelpFormatter (org.apache.commons.cli.HelpFormatter)92 Path (org.apache.hadoop.fs.Path)40 Option (org.apache.commons.cli.Option)39 IOException (java.io.IOException)32 Job (org.apache.hadoop.mapreduce.Job)27 File (java.io.File)24 Configuration (org.apache.hadoop.conf.Configuration)19 FileInputStream (java.io.FileInputStream)14 ArrayList (java.util.ArrayList)14 Properties (java.util.Properties)13 FileSystem (org.apache.hadoop.fs.FileSystem)11 MissingArgumentException (org.apache.commons.cli.MissingArgumentException)9 FileNotFoundException (java.io.FileNotFoundException)7 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)6