opt.addOption("d", "dbname", true, "DB name");
opt.addOption(null, "drop-tables", false, "Remove database schema (drop all data)");
opt.addOption("f", "fbp", true, "FindBugsProject file");
+ opt.addOption(null, "help", false, "Display help message and exit");
opt.addOption("h", "host", true, "DB hostname");
opt.addOption("j", "project", true, "proJect name");
opt.addOption("n", "number", true, "Build number (version)");
try {
CommandLine line = new GnuParser().parse(opt, args);
+
if (line.hasOption("c")) {
m_configFile = new File(line.getOptionValue("c"));
}
if (line.hasOption("h")) {
m_config.setDbHost(line.getOptionValue("h"));
}
+ if (line.hasOption("help")) {
+ usage(pw, opt);
+ return false;
+ }
if (line.hasOption("j")) {
m_projName = line.getOptionValue("j");
}
return false;
}
+ // Check for required parameters
+ if (m_removeSchema) {
+ // No other parameters required
+ return true;
+ }
+ if (null == m_fbp) {
+ pw.println(trans(CfbBundle.MUST_SPECIFY_FBP_FILE));
+ pw.println(trans(CfbBundle.INVOKE_WITH_HELP_FOR_HELP));
+ return false;
+ }
+ if (null == m_projName) {
+ m_projName = m_fbp.getName();
+ if (m_projName.endsWith(".fbp")) {
+ m_projName = m_projName.substring(0, m_projName.length() - 4);
+ }
+ }
+
return true;
}
+ // Note that this leverages commons-cli's HelpFormatter to
+ // generate the usage message. It will always be in English.
+ // If we want to localize that, we'd need to recode this,
+ // and also translate the parameter descriptions in
+ // createOptions().
void usage(PrintWriter pw, Options opt) {
HelpFormatter help = new HelpFormatter();
help.printHelp(pw, 80, getClass().getName(), "", opt, 0, 0, "", true);
return getBundle(m_locale).get(key, params);
}
- String getenv(String varName) {
- // This is a separate function so that we can override it at unit test time
- return System.getenv(varName);
- }
-
String getProperty(String propName) {
// This is a separate function so that we can override it at unit test time
return System.getProperty(propName);
}
void initArgs() {
- String findBugsDir = getenv("FINDBUGS_HOME");
+ String findBugsDir = Env.get("FINDBUGS_HOME");
if (null != findBugsDir) {
m_fbDir = new File(findBugsDir);
}