use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class SpamExtract method main.
public static void main(String[] args) throws ServiceException, HttpException, SoapFaultException, IOException {
CommandLine cl = parseArgs(args);
if (cl.hasOption('D')) {
CliUtil.toolSetup("DEBUG");
} else {
CliUtil.toolSetup("INFO");
}
if (cl.hasOption('v')) {
verbose = true;
}
boolean optDelete = cl.hasOption('d');
if (!cl.hasOption('o')) {
usage("must specify directory to extract messages to");
}
String optDirectory = cl.getOptionValue('o');
File outputDirectory = new File(optDirectory);
if (!outputDirectory.exists()) {
LOG.info("Creating directory: " + optDirectory);
outputDirectory.mkdirs();
if (!outputDirectory.exists()) {
LOG.error("could not create directory " + optDirectory);
System.exit(2);
}
}
String optAdminUser;
if (cl.hasOption('a')) {
optAdminUser = cl.getOptionValue('a');
} else {
optAdminUser = LC.zimbra_ldap_user.value();
}
String optAdminPassword;
if (cl.hasOption('p')) {
optAdminPassword = cl.getOptionValue('p');
} else {
optAdminPassword = LC.zimbra_ldap_password.value();
}
String optQuery = "in:inbox";
if (cl.hasOption('q')) {
optQuery = cl.getOptionValue('q');
}
Account account = getAccount(cl);
if (account == null) {
System.exit(1);
}
boolean optRaw = cl.hasOption('r');
if (verbose) {
LOG.info("Extracting from account " + account.getName());
}
Server server = Provisioning.getInstance().getServer(account);
String optAdminURL;
if (cl.hasOption('u')) {
optAdminURL = cl.getOptionValue('u');
} else {
optAdminURL = getSoapURL(server, true);
}
String adminAuthToken = getAdminAuthToken(optAdminURL, optAdminUser, optAdminPassword);
String authToken = getDelegateAuthToken(optAdminURL, account, adminAuthToken);
BATCH_SIZE = Provisioning.getInstance().getLocalServer().getAntispamExtractionBatchSize();
SLEEP_TIME = Provisioning.getInstance().getLocalServer().getAntispamExtractionBatchDelay();
extract(authToken, account, server, optQuery, outputDirectory, optDelete, optRaw);
}
use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class SpamExtract method parseArgs.
private static CommandLine parseArgs(String[] args) {
CommandLineParser parser = new GnuParser();
CommandLine cl = null;
try {
cl = parser.parse(options, args);
} catch (ParseException pe) {
usage(pe.getMessage());
}
if (cl.hasOption("h")) {
usage(null);
}
return cl;
}
use of org.apache.commons.cli.CommandLine 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.CommandLine 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.CommandLine 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;
}
Aggregations