Search in sources :

Example 26 with PosixParser

use of org.apache.commons.cli.PosixParser in project opennms by OpenNMS.

the class CheckWmi method main.

/**
	 * <p>main</p>
	 *
	 * @param args an array of {@link java.lang.String} objects.
	 * @throws org.apache.commons.cli.ParseException if any.
	 */
public static void main(final String[] args) throws ParseException {
    final Options options = new Options();
    options.addOption("domain", true, "the NT/AD domain the credentials belong to");
    options.addOption("wmiClass", true, "the object class in WMI to query");
    options.addOption("wmiNamespace", true, "the namespace in WMI to use (default: " + WmiParams.WMI_DEFAULT_NAMESPACE + ")");
    options.addOption("wmiObject", true, "the object to query in WMI");
    options.addOption("wmiWql", true, "the query string to execute in WMI");
    options.addOption("op", true, "compare operation: NOOP, EQ, NEQ, GT, LT");
    options.addOption("value", true, "the value to compare to");
    options.addOption("matchType", true, "type of matching for multiple results: all, none, some, one");
    final CommandLineParser parser = new PosixParser();
    final CommandLine cmd = parser.parse(options, args);
    @SuppressWarnings("unchecked") List<String> arguments = (List<String>) cmd.getArgList();
    if (arguments.size() < 3) {
        usage(options, cmd);
        System.exit(1);
    }
    final String host = arguments.remove(0);
    final String user = arguments.remove(0);
    final String pass = arguments.remove(0);
    String wmiClass = "";
    if (cmd.hasOption("wmiClass")) {
        wmiClass = cmd.getOptionValue("wmiClass");
    }
    /* else {
			usage(options, cmd);
			System.exit(1);
		}*/
    String wmiObject = "";
    if (cmd.hasOption("wmiObject")) {
        wmiObject = cmd.getOptionValue("wmiObject");
    } else {
        usage(options, cmd);
        System.exit(1);
    }
    String wmiNamespace = WmiParams.WMI_DEFAULT_NAMESPACE;
    if (cmd.hasOption("wmiNamespace")) {
        wmiNamespace = cmd.getOptionValue("wmiNamespace");
    }
    String wmiWql = "";
    if (cmd.hasOption("wmiWql")) {
        wmiWql = cmd.getOptionValue("wmiWql");
    }
    /*else {
            usage(options, cmd);
            System.exit(1);
        } */
    String compVal = "";
    if (cmd.hasOption("value")) {
        compVal = cmd.getOptionValue("value");
    } else {
        usage(options, cmd);
        System.exit(1);
    }
    String compOp = "";
    if (cmd.hasOption("op")) {
        compOp = cmd.getOptionValue("op");
    } else {
        usage(options, cmd);
        System.exit(1);
    }
    String domain = "";
    if (cmd.hasOption("domain")) {
        domain = cmd.getOptionValue("domain");
    }
    String matchType = "all";
    if (cmd.hasOption("matchType")) {
        matchType = cmd.getOptionValue("matchType");
    }
    try {
        // Hold the WMI objects from the results.
        List<Object> wmiObjects;
        // Create the check parameters holder.
        WmiParams clientParams;
        if (wmiWql == null || wmiWql.length() == 0)
            clientParams = new WmiParams(WmiParams.WMI_OPERATION_INSTANCEOF, compVal, compOp, wmiClass, wmiObject);
        else
            clientParams = new WmiParams(WmiParams.WMI_OPERATION_WQL, compVal, compOp, wmiWql, wmiObject);
        // Create the WMI Manager
        final WmiManager mgr = new WmiManager(host, user, pass, domain, matchType);
        mgr.setNamespace(wmiNamespace);
        // Connect to the WMI server.
        mgr.init();
        // Perform the operation specified in the parameters.
        final WmiResult result = mgr.performOp(clientParams);
        // And retrieve the WMI objects from the results.
        wmiObjects = result.getResponse();
        // Now output a brief report of the check results.
        System.out.println("Checking: " + wmiWql + " for " + wmiObject + " Op: " + compOp + " Val: " + compVal);
        System.out.println("Check results: " + WmiResult.convertStateToString(result.getResultCode()) + " (" + wmiObjects.size() + ")");
        for (int i = 0; i < wmiObjects.size(); i++) {
            System.out.println("Result for (" + (i + 1) + ") " + wmiClass + "\\" + wmiObject + ": " + wmiObjects.get(i));
        }
        // Disconnect when we're done.
        mgr.close();
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : Options(org.apache.commons.cli.Options) PosixParser(org.apache.commons.cli.PosixParser) ParseException(org.apache.commons.cli.ParseException) CommandLine(org.apache.commons.cli.CommandLine) List(java.util.List) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Example 27 with PosixParser

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

the class SoapApiChangeLog method main.

/**
     * Main
     */
public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    Option opt;
    opt = new Option("d", ARG_OUTPUT_DIR, true, "Output directory for changelog information");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("t", ARG_TEMPLATES_DIR, true, "Directory containing Freemarker templates");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("b", ARG_APIDESC_BASELINE_JSON, true, "JSON file - description of baseline SOAP API");
    opt.setRequired(true);
    options.addOption(opt);
    opt = new Option("c", ARG_APIDESC_CURRENT_JSON, true, "JSON file - description of current SOAP API");
    opt.setRequired(true);
    options.addOption(opt);
    CommandLine cl = null;
    try {
        cl = parser.parse(options, args, true);
    } catch (ParseException pe) {
        System.err.println("error: " + pe.getMessage());
        System.exit(2);
    }
    String baselineApiDescriptionJson = cl.getOptionValue('b');
    String currentApiDescriptionJson = cl.getOptionValue('c');
    SoapApiChangeLog clog = new SoapApiChangeLog(cl.getOptionValue('d'), cl.getOptionValue('t'));
    clog.setBaselineDesc(SoapApiDescription.deserializeFromJson(new File(baselineApiDescriptionJson)));
    clog.setCurrentDesc(SoapApiDescription.deserializeFromJson(new File(currentApiDescriptionJson)));
    clog.makeChangeLogDataModel();
    clog.writeChangelog();
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) JsonParseException(org.codehaus.jackson.JsonParseException) ParseException(org.apache.commons.cli.ParseException) File(java.io.File)

Example 28 with PosixParser

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

the class WaitSetValidator method main.

/**
     * @param args
     */
public static void main(String[] args) {
    CliUtil.toolSetup();
    WaitSetValidator t = new WaitSetValidator();
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption("i", "id", true, "Wait Set ID");
    options.addOption("h", "host", true, "Hostname");
    options.addOption("u", "user", true, "Username");
    options.addOption("p", "pw", true, "Password");
    options.addOption("?", "help", false, "Help");
    options.addOption("v", "verbose", false, "Verbose");
    CommandLine cl = null;
    boolean err = false;
    String[] hosts;
    String[] ids;
    try {
        cl = parser.parse(options, args, true);
    } catch (ParseException pe) {
        printError("error: " + pe.getMessage());
        err = true;
    }
    if (err || cl.hasOption('?')) {
        t.usage();
    }
    String id = null, host = null, user = null, pw = null;
    if (!cl.hasOption('i'))
        t.usage();
    id = cl.getOptionValue('i');
    if (cl.hasOption('h'))
        host = cl.getOptionValue('h');
    else
        host = "http://localhost:7071/service/admin";
    if (cl.hasOption('u'))
        user = cl.getOptionValue('u');
    else
        user = "admin";
    if (cl.hasOption('p'))
        pw = cl.getOptionValue('p');
    else
        pw = "test123";
    if (cl.hasOption('v'))
        t.setVerbose(true);
    hosts = host.split(",");
    ids = id.split(",");
    if (hosts.length != ids.length) {
        System.err.println("If multiple hosts or ids are specified, the same number is required of each");
        System.exit(3);
    }
    for (int i = 0; i < hosts.length; i++) {
        if (i > 0)
            System.out.println("\n\n");
        System.out.println("Checking server " + hosts[i] + " waitsetId=" + ids[i]);
        t.run(ids[i], hosts[i], user, pw);
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 29 with PosixParser

use of org.apache.commons.cli.PosixParser in project aerospike-client-java by aerospike.

the class Main method main.

/**
	 * Main entry point.
	 */
public static void main(String[] args) {
    try {
        Options options = new Options();
        options.addOption("h", "host", true, "List of seed hosts in format:\n" + "hostname1[:tlsname][:port1],...\n" + "The tlsname is only used when connecting with a secure TLS enabled server. " + "If the port is not specified, the default port is used.\n" + "IPv6 addresses must be enclosed in square brackets.\n" + "Default: localhost\n" + "Examples:\n" + "host1\n" + "host1:3000,host2:3000\n" + "192.168.1.10:cert1:3000,[2001::1111]:cert2:3000\n");
        options.addOption("p", "port", true, "Server default port (default: 3000)");
        options.addOption("U", "user", true, "User name");
        options.addOption("P", "password", true, "Password");
        options.addOption("n", "namespace", true, "Namespace (default: test)");
        options.addOption("s", "set", true, "Set name. Use 'empty' for empty set (default: demoset)");
        options.addOption("tls", "tlsEnable", false, "Use TLS/SSL sockets");
        options.addOption("tp", "tlsProtocols", true, "Allow TLS protocols\n" + "Values:  SSLv3,TLSv1,TLSv1.1,TLSv1.2 separated by comma\n" + "Default: TLSv1.2");
        options.addOption("tlsCiphers", "tlsCipherSuite", true, "Allow TLS cipher suites\n" + "Values:  cipher names defined by JVM separated by comma\n" + "Default: null (default cipher list provided by JVM)");
        options.addOption("tr", "tlsRevoke", true, "Revoke certificates identified by their serial number\n" + "Values:  serial numbers separated by comma\n" + "Default: null (Do not revoke certificates)");
        options.addOption("te", "tlsEncryptOnly", false, "Enable TLS encryption and disable TLS certificate validation");
        options.addOption("netty", false, "Use Netty NIO event loops for async examples");
        options.addOption("nettyEpoll", false, "Use Netty epoll event loops for async examples (Linux only)");
        options.addOption("g", "gui", false, "Invoke GUI to selectively run tests.");
        options.addOption("d", "debug", false, "Run in debug mode.");
        options.addOption("u", "usage", false, "Print usage.");
        CommandLineParser parser = new PosixParser();
        CommandLine cl = parser.parse(options, args, false);
        if (args.length == 0 || cl.hasOption("u")) {
            logUsage(options);
            return;
        }
        Parameters params = parseParameters(cl);
        String[] exampleNames = cl.getArgs();
        if ((exampleNames.length == 0) && (!cl.hasOption("g"))) {
            logUsage(options);
            return;
        }
        // Check for all.
        for (String exampleName : exampleNames) {
            if (exampleName.equalsIgnoreCase("all")) {
                exampleNames = ExampleNames;
                break;
            }
        }
        if (cl.hasOption("netty")) {
            params.eventLoopType = EventLoopType.NETTY_NIO;
        }
        if (cl.hasOption("nettyEpoll")) {
            params.eventLoopType = EventLoopType.NETTY_EPOLL;
        }
        if (cl.hasOption("d")) {
            Log.setLevel(Level.DEBUG);
        }
        if (cl.hasOption("g")) {
            GuiDisplay.startGui(params);
        } else {
            Console console = new Console();
            runExamples(console, params, exampleNames);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Example 30 with PosixParser

use of org.apache.commons.cli.PosixParser in project apex-core by apache.

the class ApexCli method getGetAppPackageInfoCommandLineInfo.

static GetAppPackageInfoCommandLineInfo getGetAppPackageInfoCommandLineInfo(String[] args) throws ParseException {
    CommandLineParser parser = new PosixParser();
    GetAppPackageInfoCommandLineInfo result = new GetAppPackageInfoCommandLineInfo();
    CommandLine line = parser.parse(GET_APP_PACKAGE_INFO_OPTIONS, args);
    result.provideDescription = line.hasOption("withDescription");
    return result;
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Aggregations

PosixParser (org.apache.commons.cli.PosixParser)79 CommandLine (org.apache.commons.cli.CommandLine)74 CommandLineParser (org.apache.commons.cli.CommandLineParser)61 Options (org.apache.commons.cli.Options)52 ParseException (org.apache.commons.cli.ParseException)50 IOException (java.io.IOException)19 File (java.io.File)17 HelpFormatter (org.apache.commons.cli.HelpFormatter)13 SystemExitException (org.apache.openejb.cli.SystemExitException)7 Properties (java.util.Properties)6 Parser (org.apache.commons.cli.Parser)6 List (java.util.List)5 Option (org.apache.commons.cli.Option)5 Path (org.apache.hadoop.fs.Path)4 EOFException (java.io.EOFException)3 InputStream (java.io.InputStream)3 InitialContext (javax.naming.InitialContext)3 NamingException (javax.naming.NamingException)3 ServiceUnavailableException (javax.naming.ServiceUnavailableException)3 Configuration (org.apache.hadoop.conf.Configuration)3