@Test public void testNoArgs() throws Exception { Main main = new Main(new TestCommand()); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bytes); int rc = main.run(null, out, null, Collections.<String>emptyList()); assertThat(rc, is(-1)); assertThat(bytes.toString(), containsString("Usage: whirr COMMAND")); assertThat(bytes.toString(), containsString("test-command test description")); }
int run(InputStream in, PrintStream out, PrintStream err, List<String> list) throws Exception { if (list.isEmpty()) { printUsage(out); return -1; } Command command = commandMap.get(list.get(0)); if (command == null) { err.printf("Unrecognized command '%s'\n", list.get(0)); err.println(); printUsage(err); return -1; } return command.run(in, out, err, list.subList(1, list.size())); }
Main { int run(InputStream in, PrintStream out, PrintStream err, List<String> list) throws Exception { if (list.isEmpty()) { printUsage(out); return -1; } Command command = commandMap.get(list.get(0)); if (command == null) { err.printf("Unrecognized command '%s'\n", list.get(0)); err.println(); printUsage(err); return -1; } return command.run(in, out, err, list.subList(1, list.size())); } }
Main { int run(InputStream in, PrintStream out, PrintStream err, List<String> list) throws Exception { if (list.isEmpty()) { printUsage(out); return -1; } Command command = commandMap.get(list.get(0)); if (command == null) { err.printf("Unrecognized command '%s'\n", list.get(0)); err.println(); printUsage(err); return -1; } return command.run(in, out, err, list.subList(1, list.size())); } Main(Command... commands);   Main(Iterable<Command> commands); }
Main { int run(InputStream in, PrintStream out, PrintStream err, List<String> list) throws Exception { if (list.isEmpty()) { printUsage(out); return -1; } Command command = commandMap.get(list.get(0)); if (command == null) { err.printf("Unrecognized command '%s'\n", list.get(0)); err.println(); printUsage(err); return -1; } return command.run(in, out, err, list.subList(1, list.size())); } Main(Command... commands);   Main(Iterable<Command> commands); static void main(String... args); }
Main { int run(InputStream in, PrintStream out, PrintStream err, List<String> list) throws Exception { if (list.isEmpty()) { printUsage(out); return -1; } Command command = commandMap.get(list.get(0)); if (command == null) { err.printf("Unrecognized command '%s'\n", list.get(0)); err.println(); printUsage(err); return -1; } return command.run(in, out, err, list.subList(1, list.size())); } Main(Command... commands);   Main(Iterable<Command> commands); static void main(String... args);  }