Search in sources :

Example 21 with PosixParser

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

the class VmwareConfigBuilder method main.

public static void main(String[] args) throws ParseException {
    String hostname = null;
    String username = null;
    String password = null;
    String rrdRepository = null;
    final Options options = new Options();
    options.addOption("rrdRepository", true, "set rrdRepository path for generated config files, default: '/opt/opennms/share/rrd/snmp/'");
    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);
    }
    hostname = arguments.remove(0);
    username = arguments.remove(0);
    password = arguments.remove(0);
    if (cmd.hasOption("rrdRepository")) {
        rrdRepository = cmd.getOptionValue("rrdRepository");
    } else {
        rrdRepository = "/opt/opennms/share/rrd/snmp/";
    }
    TrustManager[] trustAllCerts = new TrustManager[] { new AnyServerX509TrustManager() };
    SSLContext sc = null;
    try {
        sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, null);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HostnameVerifier hv = new HostnameVerifier() {

        @Override
        public boolean verify(String urlHostName, SSLSession session) {
            return true;
        }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
    VmwareConfigBuilder vmwareConfigBuilder;
    vmwareConfigBuilder = new VmwareConfigBuilder(hostname, username, password);
    try {
        vmwareConfigBuilder.generateData(rrdRepository);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Options(org.apache.commons.cli.Options) PosixParser(org.apache.commons.cli.PosixParser) SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) ParseException(org.apache.commons.cli.ParseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) TrustManager(javax.net.ssl.TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier) CommandLine(org.apache.commons.cli.CommandLine) List(java.util.List) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Example 22 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 23 with PosixParser

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

the class ConfigTester method main.

public static void main(String[] argv) {
    FilterDaoFactory.setInstance(new ConfigTesterFilterDao());
    DataSourceFactory.setInstance(new ConfigTesterDataSource());
    ConfigTester tester = BeanUtils.getBean("configTesterContext", "configTester", ConfigTester.class);
    final CommandLineParser parser = new PosixParser();
    final Options options = new Options();
    options.addOption("h", "help", false, "print this help and exit");
    options.addOption("a", "all", false, "check all supported configuration files");
    options.addOption("l", "list", false, "list supported configuration files and exit");
    options.addOption("v", "verbose", false, "list each configuration file as it is tested");
    options.addOption("i", "ignore-unknown", false, "ignore unknown configuration files and continue processing");
    final CommandLine line;
    try {
        line = parser.parse(options, argv, false);
    } catch (ParseException e) {
        System.err.println("Invalid usage: " + e.getMessage());
        System.err.println("Run 'config-tester -h' for help.");
        System.exit(1);
        // not reached; here to eliminate warning on line being uninitialized
        return;
    }
    final boolean ignoreUnknown = line.hasOption("i");
    if ((line.hasOption('l') || line.hasOption('h') || line.hasOption('a'))) {
        if (line.getArgList().size() > 0) {
            System.err.println("Invalid usage: No arguments allowed when using the '-a', '-h', or '-l' options.");
            System.err.println("Run 'config-tester -h' for help.");
            System.exit(1);
        }
    } else {
        if (line.getArgs().length == 0) {
            System.err.println("Invalid usage: too few arguments.  Use the '-h' option for help.");
            System.exit(1);
        }
    }
    boolean verbose = line.hasOption('v');
    DataSourceFactory.setInstance(new ConfigTesterDataSource());
    if (line.hasOption('l')) {
        System.out.println("Supported configuration files: ");
        for (String configFile : tester.getConfigs().keySet()) {
            System.out.println("    " + configFile);
        }
        System.out.println("Note: not all OpenNMS configuration files are currently supported.");
    } else if (line.hasOption('h')) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("config-tester -a\nOR: config-tester [config files]\nOR: config-tester -l\nOR: config-tester -h", options);
    } else if (line.hasOption('a')) {
        for (String configFile : tester.getConfigs().keySet()) {
            tester.testConfig(configFile, verbose, ignoreUnknown);
        }
    } else {
        for (String configFile : line.getArgs()) {
            tester.testConfig(configFile, verbose, ignoreUnknown);
        }
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) 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 24 with PosixParser

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

the class Main method parseArguments.

private void parseArguments(String[] args) throws ParseException {
    Options options = new Options();
    options.addOption("h", "help", false, "this help");
    options.addOption("d", "debug", false, "write debug messages to the log");
    options.addOption("g", "gui", false, "start a GUI (default: false)");
    options.addOption("i", "disable-icmp", false, "disable ICMP/ping (overrides -Dorg.opennms.netmgt.icmp.pingerClass=)");
    options.addOption("l", "location", true, "the location name of this remote poller");
    options.addOption("u", "url", true, "the URL for OpenNMS (example: https://server-name/opennms-remoting)");
    options.addOption("n", "name", true, "the name of the user to connect as");
    options.addOption("p", "password", true, "the password to use when connecting");
    options.addOption("s", "scan-report", false, "perform a single scan report instead of running the polling engine");
    CommandLineParser parser = new PosixParser();
    CommandLine cl = parser.parse(options, args);
    if (cl.hasOption("h")) {
        usage(options);
        System.exit(1);
    }
    if (cl.hasOption("d")) {
    }
    if (cl.hasOption("i")) {
        m_disableIcmp = true;
    }
    if (cl.hasOption("l")) {
        m_locationName = cl.getOptionValue("l");
    }
    if (cl.hasOption("u")) {
        String arg = cl.getOptionValue("u").toLowerCase();
        try {
            m_uri = new URI(arg);
        } catch (URISyntaxException e) {
            usage(options);
            e.printStackTrace();
            System.exit(2);
        }
    } else {
        usage(options);
        System.exit(3);
    }
    if (cl.hasOption("g")) {
        m_gui = true;
    }
    if (cl.hasOption("s")) {
        m_scanReport = true;
    }
    if (cl.hasOption("n")) {
        m_username = cl.getOptionValue("n");
        m_password = cl.getOptionValue("p");
        if (m_password == null) {
            m_password = "";
        }
    }
    // to optionally get it from system properties
    if (m_username == null) {
        m_username = System.getProperty("opennms.poller.server.username");
        if (m_username != null) {
            m_password = System.getProperty("opennms.poller.server.password");
            if (m_password == null) {
                m_password = "";
            }
        }
    }
}
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) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 25 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)103 CommandLine (org.apache.commons.cli.CommandLine)97 CommandLineParser (org.apache.commons.cli.CommandLineParser)67 Options (org.apache.commons.cli.Options)56 ParseException (org.apache.commons.cli.ParseException)51 File (java.io.File)24 IOException (java.io.IOException)20 HelpFormatter (org.apache.commons.cli.HelpFormatter)16 Optional (java.util.Optional)10 Test (org.junit.Test)9 List (java.util.List)8 Configuration (org.apache.hadoop.conf.Configuration)8 GenericOptionsParser (org.apache.hadoop.util.GenericOptionsParser)7 SystemExitException (org.apache.openejb.cli.SystemExitException)7 Option (org.apache.commons.cli.Option)6 Parser (org.apache.commons.cli.Parser)6 Properties (java.util.Properties)5 Path (org.apache.hadoop.fs.Path)5 ArrayList (java.util.ArrayList)4 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)4