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