X-Git-Url: http://jaekl.net/gitweb/?p=cfb.git;a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2FCFB.java;h=eeb2a47afd7feca1e30a9dc7eb951e48578ef769;hp=c6c995d41cf70e66d9ecdb54329fca321b18cd3c;hb=7ef6c36cd147216c5354082b11aa33cf6b5c6f49;hpb=59715b74a1ef7cb3fcdb48544b6f4f2cf8208805 diff --git a/prod/net/jaekl/cfb/CFB.java b/prod/net/jaekl/cfb/CFB.java index c6c995d..eeb2a47 100644 --- a/prod/net/jaekl/cfb/CFB.java +++ b/prod/net/jaekl/cfb/CFB.java @@ -94,6 +94,7 @@ public class CFB { 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)"); @@ -110,6 +111,7 @@ public class CFB { try { CommandLine line = new GnuParser().parse(opt, args); + if (line.hasOption("c")) { m_configFile = new File(line.getOptionValue("c")); } @@ -122,6 +124,10 @@ public class CFB { 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"); } @@ -147,9 +153,31 @@ public class CFB { 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); @@ -159,11 +187,6 @@ public class CFB { 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); @@ -174,7 +197,7 @@ public class CFB { } void initArgs() { - String findBugsDir = getenv("FINDBUGS_HOME"); + String findBugsDir = Env.get("FINDBUGS_HOME"); if (null != findBugsDir) { m_fbDir = new File(findBugsDir); }