use of org.apache.commons.cli.HelpFormatter in project opennms by OpenNMS.
the class SystemReport method main.
/**
* @param args
*/
public static void main(final String[] args) throws Exception {
final String tempdir = System.getProperty("java.io.tmpdir");
// pull out -D defines first
for (final String arg : args) {
if (arg.startsWith("-D") && arg.contains("=")) {
final Matcher m = m_pattern.matcher(arg);
if (m.matches()) {
System.setProperty(m.group(1), m.group(2));
}
}
}
if (System.getProperty("opennms.home") == null) {
System.setProperty("opennms.home", tempdir);
}
if (System.getProperty("rrd.base.dir") == null) {
System.setProperty("rrd.base.dir", tempdir);
}
if (System.getProperty("rrd.binary") == null) {
System.setProperty("rrd.binary", "/usr/bin/rrdtool");
}
final CommandLineParser parser = new PosixParser();
final Options options = new Options();
options.addOption("h", "help", false, "this help");
options.addOption("D", "define", true, "define a java property");
options.addOption("p", "list-plugins", false, "list the available system report plugins");
options.addOption("u", "use-plugins", true, "select the plugins to output");
options.addOption("l", "list-formats", false, "list the available output formats");
options.addOption("f", "format", true, "the format to output");
options.addOption("o", "output", true, "the file to write output to");
final CommandLine line = parser.parse(options, args, false);
final Set<String> plugins = new LinkedHashSet<String>();
final SystemReport report = new SystemReport();
// help
if (line.hasOption("h")) {
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("system-report.sh [options]", options);
System.exit(0);
}
// format and output file
if (line.hasOption("f")) {
report.setFormat(line.getOptionValue("f"));
}
if (line.hasOption("o")) {
report.setOutput(line.getOptionValue("o"));
}
if (line.hasOption("u")) {
final String value = line.getOptionValue("u");
if (value != null) {
for (final String s : value.split(",+")) {
plugins.add(s);
}
}
}
// final command
if (line.hasOption("p")) {
report.listPlugins();
} else if (line.hasOption("l")) {
report.listFormats();
} else {
report.writePluginData(plugins);
}
}
use of org.apache.commons.cli.HelpFormatter in project opennms by OpenNMS.
the class VmwareRequisitionTool method usage.
private static void usage(final Options options, final CommandLine cmd, final String error, final Exception e) {
final HelpFormatter formatter = new HelpFormatter();
final PrintWriter pw = new PrintWriter(System.out);
if (error != null) {
pw.println("An error occurred: " + error + "\n");
}
StringBuffer sb = new StringBuffer();
sb.append("Usage: VmwareRequisitionTool vmware://username:password@host[/foreign-source]?keyA=valueA;keyB=valueB;...\n");
sb.append(" Note: in case the credentials are not specified, they should exist on vmware.config.xml\n");
formatter.printHelp(sb.toString(), options);
if (e != null) {
pw.println(e.getMessage());
e.printStackTrace(pw);
}
pw.close();
}
use of org.apache.commons.cli.HelpFormatter in project opennms by OpenNMS.
the class CheckWmi method usage.
private static void usage(final Options options, final CommandLine cmd, final String error, final Exception e) {
final HelpFormatter formatter = new HelpFormatter();
final PrintWriter pw = new PrintWriter(System.out);
if (error != null) {
pw.println("An error occurred: " + error + "\n");
}
formatter.printHelp("usage: CheckWmi [options] <host> <username> <password>", options);
if (e != null) {
pw.println(e.getMessage());
e.printStackTrace(pw);
}
pw.close();
}
use of org.apache.commons.cli.HelpFormatter in project opennms by OpenNMS.
the class Main method usage.
private static void usage(Options o) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(Main.class.getName() + " -u [URL] [options]", o);
}
use of org.apache.commons.cli.HelpFormatter in project sqflint by SkaceKamen.
the class SQFLint method main.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Options options = new Options();
CommandLineParser cmdParser = new DefaultParser();
CommandLine cmd;
options.addOption("j", "json", false, "output json");
options.addOption("v", "variables", false, "output variables info (only in json mode)");
options.addOption("e", "error", false, "stop on error");
options.addOption("nw", "no-warning", false, "skip warnings");
options.addOption("we", "warning-as-error", false, "output warnings as errors");
options.addOption("oc", "output-code", false, "output ERR return code when any error is encountered");
options.addOption("cp", "check-paths", false, "check for path existence for exevm and preprocessfile");
options.addOption("r", "root", true, "root for path checking (path to file is used if file is specified)");
options.addOption("h", "help", false, "");
options.addOption("iv", "ignore-variables", true, "ignored variables are treated as internal command");
options.addOption("s", "server", false, "run as server");
options.addOption("ip", "include-prefix", true, "adds include prefix override, format: prefix,path_to_use");
try {
cmd = cmdParser.parse(options, args);
} catch (org.apache.commons.cli.ParseException ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
return;
}
if (cmd.hasOption("h") || cmd.getArgs().length > 1) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("sqflint [OPTIONS] [FILE]", "Scans SQF file for errors and potential problems.", options, "Spaghetti");
return;
}
SQFPreprocessor preprocessor;
Linter linter;
String contents = null;
String root = null;
String[] ignoredVariables = new String[0];
if (cmd.hasOption("r")) {
root = cmd.getOptionValue("r");
}
if (cmd.hasOption("iv")) {
ignoredVariables = cmd.getOptionValues("iv");
}
cz.zipek.sqflint.linter.Options linterOptions;
try {
linterOptions = new cz.zipek.sqflint.linter.Options();
} catch (IOException ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
return;
}
if (cmd.hasOption("ip")) {
for (String value : cmd.getOptionValues("ip")) {
String[] split = value.split(",");
if (split.length != 2) {
System.out.println("Invalid include prefix : " + value);
System.out.println("Include prefix format is: prefix,include_path");
return;
}
linterOptions.getIncludePaths().put(split[0], split[1]);
}
}
linterOptions.setRootPath(root);
linterOptions.addIgnoredVariables(ignoredVariables);
if (cmd.hasOption("j")) {
linterOptions.setOutputFormatter(new JSONOutput());
}
linterOptions.setStopOnError(cmd.hasOption("e"));
linterOptions.setSkipWarnings(cmd.hasOption("nw"));
linterOptions.setOutputVariables(cmd.hasOption("v"));
linterOptions.setExitCodeEnabled(cmd.hasOption("oc"));
linterOptions.setWarningAsError(cmd.hasOption("we"));
linterOptions.setCheckPaths(cmd.hasOption("cp"));
preprocessor = new SQFPreprocessor(linterOptions);
if (!cmd.hasOption("s")) {
if (cmd.getArgs().length == 0) {
try {
String filename = null;
if (root != null) {
filename = Paths.get(root).resolve("file.sqf").toString();
}
contents = preprocessor.process(System.in, filename, false);
} catch (Exception ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
return;
}
} else if (cmd.getArgs().length == 1) {
String filename = cmd.getArgs()[0];
if (root == null) {
root = Paths.get(filename).toAbsolutePath().getParent().toString();
}
try {
contents = preprocessor.process(new java.io.FileInputStream(filename), filename, true);
} catch (Exception ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
return;
}
}
linterOptions.setRootPath(root);
if (contents != null) {
linter = new Linter(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)), linterOptions);
linter.setPreprocessor(preprocessor);
try {
System.exit(linter.start());
} catch (IOException ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
}
}
} else {
SQFLintServer server = new SQFLintServer(linterOptions);
server.start();
}
}
Aggregations