Search in sources :

Example 81 with CommandLine

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);
}
Also used : Account(com.zimbra.cs.account.Account) CommandLine(org.apache.commons.cli.CommandLine) Server(com.zimbra.cs.account.Server) File(java.io.File)

Example 82 with CommandLine

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;
}
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 83 with CommandLine

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;
}
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 84 with CommandLine

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;
}
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 85 with CommandLine

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

Aggregations

CommandLine (org.apache.commons.cli.CommandLine)968 Options (org.apache.commons.cli.Options)560 ParseException (org.apache.commons.cli.ParseException)464 CommandLineParser (org.apache.commons.cli.CommandLineParser)459 HelpFormatter (org.apache.commons.cli.HelpFormatter)259 GnuParser (org.apache.commons.cli.GnuParser)230 DefaultParser (org.apache.commons.cli.DefaultParser)213 PosixParser (org.apache.commons.cli.PosixParser)177 File (java.io.File)165 IOException (java.io.IOException)162 Test (org.junit.Test)144 Option (org.apache.commons.cli.Option)131 ArrayList (java.util.ArrayList)63 Path (org.apache.hadoop.fs.Path)60 BasicParser (org.apache.commons.cli.BasicParser)50 Configuration (org.apache.hadoop.conf.Configuration)41 Configuration (org.apache.flink.configuration.Configuration)37 HashMap (java.util.HashMap)34 List (java.util.List)34 Properties (java.util.Properties)33