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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations