use of org.apache.commons.cli.CommandLineParser in project GNS by MobilityFirst.
the class GNSInstaller method initializeOptions.
private static CommandLine initializeOptions(String[] args) throws ParseException {
Option help = new Option("help", "Prints Usage");
Option update = OptionBuilder.withArgName("installation name").hasArg().withDescription("updates GNS files and restarts servers in a installation").create("update");
Option restart = OptionBuilder.withArgName("installation name").hasArg().withDescription("restarts GNS servers in a installation").create("restart");
Option removeLogs = new Option("removeLogs", "remove paxos and Logger log files (use with -restart or -update)");
Option deleteDatabase = new Option("deleteDatabase", "delete the databases in a installation (use with -restart or -update)");
Option dataStore = OptionBuilder.withArgName("data store type").hasArg().withDescription("data store type").create("datastore");
Option scriptFile = OptionBuilder.withArgName("install script file").hasArg().withDescription("specifies the location of a bash script file that will install MongoDB and Java").create("scriptFile");
Option runscript = OptionBuilder.withArgName("installation name").hasArg().withDescription("just runs the script file").create("runscript");
Option stop = OptionBuilder.withArgName("installation name").hasArg().withDescription("stops GNS servers in a installation").create("stop");
Option root = new Option("root", "run the installation as root");
Option noopTest = new Option("noopTest", "starts noop test servers instead of GNS APP servers");
commandLineOptions = new Options();
commandLineOptions.addOption(update);
commandLineOptions.addOption(restart);
commandLineOptions.addOption(stop);
commandLineOptions.addOption(removeLogs);
commandLineOptions.addOption(deleteDatabase);
commandLineOptions.addOption(dataStore);
commandLineOptions.addOption(scriptFile);
commandLineOptions.addOption(runscript);
commandLineOptions.addOption(root);
commandLineOptions.addOption(noopTest);
commandLineOptions.addOption(help);
CommandLineParser parser = new GnuParser();
return parser.parse(commandLineOptions, args);
}
use of org.apache.commons.cli.CommandLineParser 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.CommandLineParser 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.CommandLineParser in project opennms by OpenNMS.
the class SpikeHunter method parseCmdLine.
public static void parseCmdLine(String[] argv) throws Exception {
m_options.addOption("h", "help", false, "This help text");
m_options.addOption("f", "file", true, "JRobin disk file on which to operate");
m_options.addOption("d", "ds-name", true, "Data source names on which to operate, comma-separated. If unspecified, operate on all DSes.");
m_options.addOption("a", "analysis-strategy", true, "Data analysis strategy. Defaults to percentile.");
m_options.addOption("o", "operands", true, "Operands (numeric, comma-separated) for the selected analysis strategy. Defaults to 95,5.");
m_options.addOption("r", "replacement-strategy", true, "Strategy for replacing spike samples, one of nan|previous|next, defaults to nan");
m_options.addOption("n", "dry-run", false, "Just report spikes, do not make any changes to the JRobin disk file.");
m_options.addOption("p", "dump-contents", false, "Just dump the DSes and RRAs in the JRobin disk file.");
m_options.addOption("q", "quiet", false, "Do not print any informational output");
m_options.addOption("v", "verbose", false, "Print plenty of informational output");
CommandLineParser parser = new PosixParser();
m_commandLine = parser.parse(m_options, argv);
if (m_commandLine.hasOption("h")) {
usage(m_options, m_commandLine);
System.exit(0);
}
Map<String, Integer> analysisStrategies = new HashMap<String, Integer>();
analysisStrategies.put("percentile", ANALYSIS_STRATEGIES.PERCENTILE_STRATEGY.ordinal());
Map<String, Integer> replacementStrategies = new HashMap<String, Integer>();
replacementStrategies.put("nan", REPLACEMENT_STRATEGIES.NAN_STRATEGY.ordinal());
replacementStrategies.put("previous", REPLACEMENT_STRATEGIES.PREVIOUS_STRATEGY.ordinal());
replacementStrategies.put("next", REPLACEMENT_STRATEGIES.NEXT_STRATEGY.ordinal());
m_rrdFileName = m_commandLine.getOptionValue("f");
m_dsNames = m_commandLine.getOptionValue("d", null);
m_operands = new ArrayList<Double>();
for (String operandStr : m_commandLine.getOptionValue("o", "95,5").split(",")) {
m_operands.add(Double.parseDouble(operandStr));
}
m_analysisStrategy = analysisStrategies.get(m_commandLine.getOptionValue("l", "percentile").toLowerCase());
m_replacementStrategy = replacementStrategies.get(m_commandLine.getOptionValue("r", "nan").toLowerCase());
m_dryRun = m_commandLine.hasOption("n");
m_dumpContents = m_commandLine.hasOption("p");
m_quiet = m_commandLine.hasOption("q");
m_verbose = m_commandLine.hasOption("v");
}
use of org.apache.commons.cli.CommandLineParser in project opennms by OpenNMS.
the class Mib2Events method parseCli.
public void parseCli(String[] argv) {
Options opts = new Options();
opts.addOption("m", "mib", true, "Pathname or URL of MIB file to scan for traps");
opts.addOption("b", "ueibase", true, "Base UEI for resulting events");
opts.addOption("c", "compat", false, "Turn on compatibility mode to create output as similar to mib2opennms as possible");
CommandLineParser parser = new GnuParser();
try {
CommandLine cmd = parser.parse(opts, argv);
if (cmd.hasOption('m')) {
m_mibLocation = cmd.getOptionValue('m');
} else {
printHelp("You must specify a MIB file pathname or URL");
System.exit(1);
}
if (cmd.hasOption("b")) {
m_ueiBase = cmd.getOptionValue('b');
}
if (cmd.hasOption("c")) {
m_compat = true;
}
} catch (ParseException e) {
printHelp("Failed to parse command line options");
System.exit(1);
}
}
Aggregations