public static void main(String args[]) throws Exception { CLI cli = new CLI(); CommandLine cl = cli.getCommandLine(args); if (!cl.hasOption(CLI.O_ACTION)) { cli.usage(new ParseException("missing required option " + CLI.O_ACTION), true); } String action = cl.getOptionValue(CLI.O_ACTION); if ("dump".equals(action)) { doDump(cl); } else if ("check".equals(action)) { doCheck(cl); } else { cli.usage(new ParseException("invalid option " + action), true); } }
@Test public void testUsage() { CLI command = CLIConfigurator.define(HelloClI.class); StringBuilder builder = new StringBuilder(); command.usage(builder); assertThat(builder) .containsIgnoringCase("Usage: hello -n <name>") .containsIgnoringCase("A command saying hello.") .containsIgnoringCase("A simple cli to wish you a good day. Pass your name with `--name`") .containsIgnoringCase(" -n,--name <name> your name"); }