/** * Checks if the long or short form is part of the command line options. * * @param shortForm * @param longForm * @return */ protected boolean hasOption(String shortForm, String longForm) { return getCommandLine().hasOption(shortForm) || getCommandLine().hasOption(longForm); }
protected void loadConfig(String filename, String configName) throws Exception { if (filename == null) { throw new MyConfigurationException("Error: no configuration file specified"); } setConfigurationNode(ConfigUtil.findConfiguration(filename, configName, getComponentName())); setEnvironment(null); //so it gets loaded next time it's needed. getEnvironment(); // reload it }
public void error(String x) { if (isVerbose()) { say(x); } getMyLogger().error(x); }
@Override public void debug(String x) { if (isDebugOn()) { say(x); } getMyLogger().debug(x); }
getOptions(); if (args.length == 0) { parseCommandLine(args); if (hasOption(HELP_OPTION, HELP_LONG_OPTION)) { setVerbose(false); if (hasOption(VERBOSE_OPTION, VERBOSE_LONG_OPTION)) { setVerbose(true); setDebugOn(false); if (hasOption(DEBUG_OPTION, DEBUG_LONG_OPTION)) { setDebugOn(true); if (hasOption(LOG_FILE_OPTION, LOG_FILE_LONG_OPTION)) { setLogfileName(getCommandLine().getOptionValue(LOG_FILE_LONG_OPTION)); if (hasOption(CONFIG_FILE_OPTION, CONFIG_FILE_LONG_OPTION)) { setConfigFile(getCommandLine().getOptionValue(CONFIG_FILE_OPTION));
public void initialize() { if (getConfigFile() == null || getConfigFile().length() == 0) { say("Warning: no configuration file specified. type in 'load --help' to see how to load one."); return; if (hasOption(CONFIG_NAME_OPTION, CONFIG_NAME_LONG_OPTION)) { cfgName = getCommandLine().getOptionValue(CONFIG_NAME_OPTION); if (hasOption(LOG_FILE_OPTION, LOG_FILE_LONG_OPTION)) { loggerProvider = new LoggerProvider(getLogfileName(), "cli logger", 1, 1000000, false, true, true); } else { loggerProvider = new LoggerProvider("log.xml", "cli logger", 1, 1000000, false, true, true); info("Config name = " + cfgName); info("no named for a configuration given"); } else { info("getting named configuration \"" + cfgName + "\""); loadConfig(getConfigFile(), cfgName); } catch (Exception x) { if (x instanceof RuntimeException) {
public void load(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { showLoadHelp(); return; } String fileName = null; String configName = inputLine.getArg(1); if (2 < inputLine.size()) { fileName = inputLine.getArg(2); } else { fileName = getConfigFile(); } say("loading configuration from " + fileName + ", named " + configName); info("loading configuration from " + fileName + ", named " + configName); loadConfig(fileName, configName); say("done!"); }
protected void parseCommandLine(String[] args) throws UnrecognizedOptionException, ParseException { CommandLineParser clp = new BasicParser(); try { cmd = clp.parse(getOptions(), args); } catch (UnrecognizedOptionException ux) { say("Error: unrecognized option + " + ux.getMessage()); say("Invoke with -help for more"); if (isVerbose()) { ux.printStackTrace(); } throw ux; } catch (ParseException e) { say("Error: could not parse a command line argument:" + e.getMessage()); if (isVerbose()) { e.printStackTrace(); } throw e; } }
public AbstractEnvironment getEnvironment() throws Exception { if (environment == null) { environment = getLoader().load(); } return environment; }
public void info(String x) { if (isVerbose()) { say(x); } getMyLogger().info(x); }
public void warn(String x) { if (isVerbose()) { say(x); } getMyLogger().warn(x); }