@Test public void testInstallNoParameters() throws IOException { main.run(new String[]{"install"}); String output = outputStream.toString("UTF-8"); assertTrue(output.contains("Usage: install [options]")); }
int run(String[] args) { initJCommander(); try { parseParams(jc, args); if (help) { printUsage(null); return EXIT_CODE_OK; } if (debug) { initializeDebugLogging(); } if (jc.getParsedCommand() == null) { return handleNoCommand(); } if (!commands.containsKey(jc.getParsedCommand())) { LOGGER.error("Unknown command: " + jc.getParsedCommand()); return EXIT_CODE_ERR; } Command parsedCommand = commands.get(jc.getParsedCommand()); if (CommandHelp.CLINAME.equals(parsedCommand.getName())) { printUsage(null); } else { if (parsedCommand.validateParameters()) { parsedCommand.execute(); } else { printUsage(jc.getParsedCommand()); return EXIT_CODE_ERR; } } return EXIT_CODE_OK; } catch (Exception ex) { PrintWriter writer = new PrintWriter(output); output.print("Failed to run command '" + jc.getParsedCommand() + "'."); if (ex.getMessage() != null) { output.print(" " + ex.getMessage() + ".\n"); } else { ex.printStackTrace(writer); } writer.close(); LOGGER.debug("Exception while processing", ex); return EXIT_CODE_ERR; } }
Main { int run(String[] args) { initJCommander(); try { parseParams(jc, args); if (help) { printUsage(null); return EXIT_CODE_OK; } if (debug) { initializeDebugLogging(); } if (jc.getParsedCommand() == null) { return handleNoCommand(); } if (!commands.containsKey(jc.getParsedCommand())) { LOGGER.error("Unknown command: " + jc.getParsedCommand()); return EXIT_CODE_ERR; } Command parsedCommand = commands.get(jc.getParsedCommand()); if (CommandHelp.CLINAME.equals(parsedCommand.getName())) { printUsage(null); } else { if (parsedCommand.validateParameters()) { parsedCommand.execute(); } else { printUsage(jc.getParsedCommand()); return EXIT_CODE_ERR; } } return EXIT_CODE_OK; } catch (Exception ex) { PrintWriter writer = new PrintWriter(output); output.print("Failed to run command '" + jc.getParsedCommand() + "'."); if (ex.getMessage() != null) { output.print(" " + ex.getMessage() + ".\n"); } else { ex.printStackTrace(writer); } writer.close(); LOGGER.debug("Exception while processing", ex); return EXIT_CODE_ERR; } } }
Main { int run(String[] args) { initJCommander(); try { parseParams(jc, args); if (help) { printUsage(null); return EXIT_CODE_OK; } if (debug) { initializeDebugLogging(); } if (jc.getParsedCommand() == null) { return handleNoCommand(); } if (!commands.containsKey(jc.getParsedCommand())) { LOGGER.error("Unknown command: " + jc.getParsedCommand()); return EXIT_CODE_ERR; } Command parsedCommand = commands.get(jc.getParsedCommand()); if (CommandHelp.CLINAME.equals(parsedCommand.getName())) { printUsage(null); } else { if (parsedCommand.validateParameters()) { parsedCommand.execute(); } else { printUsage(jc.getParsedCommand()); return EXIT_CODE_ERR; } } return EXIT_CODE_OK; } catch (Exception ex) { PrintWriter writer = new PrintWriter(output); output.print("Failed to run command '" + jc.getParsedCommand() + "'."); if (ex.getMessage() != null) { output.print(" " + ex.getMessage() + ".\n"); } else { ex.printStackTrace(writer); } writer.close(); LOGGER.debug("Exception while processing", ex); return EXIT_CODE_ERR; } }  }
Main { int run(String[] args) { initJCommander(); try { parseParams(jc, args); if (help) { printUsage(null); return EXIT_CODE_OK; } if (debug) { initializeDebugLogging(); } if (jc.getParsedCommand() == null) { return handleNoCommand(); } if (!commands.containsKey(jc.getParsedCommand())) { LOGGER.error("Unknown command: " + jc.getParsedCommand()); return EXIT_CODE_ERR; } Command parsedCommand = commands.get(jc.getParsedCommand()); if (CommandHelp.CLINAME.equals(parsedCommand.getName())) { printUsage(null); } else { if (parsedCommand.validateParameters()) { parsedCommand.execute(); } else { printUsage(jc.getParsedCommand()); return EXIT_CODE_ERR; } } return EXIT_CODE_OK; } catch (Exception ex) { PrintWriter writer = new PrintWriter(output); output.print("Failed to run command '" + jc.getParsedCommand() + "'."); if (ex.getMessage() != null) { output.print(" " + ex.getMessage() + ".\n"); } else { ex.printStackTrace(writer); } writer.close(); LOGGER.debug("Exception while processing", ex); return EXIT_CODE_ERR; } }  static void main(String[] args); void setOutput(PrintStream output); }
Main { int run(String[] args) { initJCommander(); try { parseParams(jc, args); if (help) { printUsage(null); return EXIT_CODE_OK; } if (debug) { initializeDebugLogging(); } if (jc.getParsedCommand() == null) { return handleNoCommand(); } if (!commands.containsKey(jc.getParsedCommand())) { LOGGER.error("Unknown command: " + jc.getParsedCommand()); return EXIT_CODE_ERR; } Command parsedCommand = commands.get(jc.getParsedCommand()); if (CommandHelp.CLINAME.equals(parsedCommand.getName())) { printUsage(null); } else { if (parsedCommand.validateParameters()) { parsedCommand.execute(); } else { printUsage(jc.getParsedCommand()); return EXIT_CODE_ERR; } } return EXIT_CODE_OK; } catch (Exception ex) { PrintWriter writer = new PrintWriter(output); output.print("Failed to run command '" + jc.getParsedCommand() + "'."); if (ex.getMessage() != null) { output.print(" " + ex.getMessage() + ".\n"); } else { ex.printStackTrace(writer); } writer.close(); LOGGER.debug("Exception while processing", ex); return EXIT_CODE_ERR; } }  static void main(String[] args); void setOutput(PrintStream output);  }