use of org.apache.commons.cli.HelpFormatter in project symmetric-ds by JumpMind.
the class SymmetricAdmin method printHelpCommand.
private void printHelpCommand(CommandLine line) {
String[] args = line.getArgs();
if (args.length > 1) {
String cmd = args[1];
HelpFormatter format = new HelpFormatter();
PrintWriter writer = new PrintWriter(System.out);
Options options = new Options();
if (!Message.containsKey("SymAdmin.Usage." + cmd)) {
System.err.println("ERROR: no help text for subcommand '" + cmd + "' was found.");
System.err.println("For a list of subcommands, use " + app + " --" + HELP + "\n");
return;
}
format.printWrapped(writer, WIDTH, "Usage: " + app + " " + cmd + " " + Message.get("SymAdmin.Usage." + cmd) + "\n");
format.printWrapped(writer, WIDTH, Message.get("SymAdmin.Help." + cmd));
if (cmd.equals(CMD_SEND_SQL) || cmd.equals(CMD_SEND_SCHEMA) || cmd.equals(CMD_RELOAD_TABLE) || cmd.equals(CMD_SEND_SCRIPT)) {
addOption(options, "n", OPTION_NODE, true);
addOption(options, "g", OPTION_NODE_GROUP, true);
}
if (cmd.equals(CMD_RELOAD_TABLE)) {
addOption(options, "c", OPTION_CATALOG, true);
addOption(options, "s", OPTION_SCHEMA, true);
addOption(options, "w", OPTION_WHERE, true);
}
if (cmd.equals(CMD_SYNC_TRIGGERS)) {
addOption(options, "o", OPTION_OUT, false);
addOption(options, "f", OPTION_FORCE, false);
}
if (cmd.equals(CMD_RELOAD_NODE)) {
addOption(options, "r", OPTION_REVERSE, false);
}
if (options.getOptions().size() > 0) {
format.printWrapped(writer, WIDTH, "\nOptions:");
format.printOptions(writer, WIDTH, options, PAD, PAD);
}
if (!ArrayUtils.contains(NO_ENGINE_REQUIRED, cmd)) {
format.printWrapped(writer, WIDTH, "\nEngine options:");
options = new Options();
super.buildOptions(options);
format.printOptions(writer, WIDTH, options, PAD, PAD);
format.printWrapped(writer, WIDTH, "\nCrypto options:");
options = new Options();
buildCryptoOptions(options);
format.printOptions(writer, WIDTH, options, PAD, PAD);
}
writer.flush();
}
}
use of org.apache.commons.cli.HelpFormatter in project symmetric-ds by JumpMind.
the class SymmetricAdmin method printHelpLine.
private void printHelpLine(PrintWriter pw, String cmd) {
String text = StringUtils.pad(" " + cmd, 23, " ", true) + Message.get("SymAdmin.Cmd." + cmd);
new HelpFormatter().printWrapped(pw, 79, 25, text);
}
use of org.apache.commons.cli.HelpFormatter 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.HelpFormatter in project opennms by OpenNMS.
the class SpikeHunter method usage.
private static void usage(Options options, CommandLine cmd, String error, Exception e) {
HelpFormatter formatter = new HelpFormatter();
PrintWriter pw = new PrintWriter(m_out);
if (error != null) {
pw.println("An error occurred: " + error + "\n");
}
formatter.printHelp("usage: spike-hunter [options]", options);
if (e != null) {
pw.println(e.getMessage());
e.printStackTrace(pw);
}
pw.close();
System.exit(0);
}
use of org.apache.commons.cli.HelpFormatter in project opennms by OpenNMS.
the class CheckNsc method usage.
private static void usage(Options options, CommandLine cmd, String error, Throwable e) {
HelpFormatter formatter = new HelpFormatter();
PrintWriter pw = new PrintWriter(System.out);
if (error != null) {
pw.println("An error occurred: " + error + "\n");
}
formatter.printHelp("usage: CheckNsc [options] host command [arguments]", options);
if (e != null) {
pw.println(e.getMessage());
e.printStackTrace(pw);
}
pw.close();
}
Aggregations