Bootstrap { static ParseCommandLineArgsResult parseCommandLineArgs(String[] args) { final ServerOptions opts = new ServerOptions(); final CommandLine cli = new CommandLine(opts); try { cli.parseArgs(args); if (cli.isUsageHelpRequested()) { cli.usage(cli.getOut()); return new ParseCommandLineArgsResult(cli.getCommandSpec().exitCodeOnUsageHelp()); } else if (cli.isVersionHelpRequested()) { cli.printVersionHelp(cli.getOut()); return new ParseCommandLineArgsResult(cli.getCommandSpec().exitCodeOnVersionHelp()); } } catch (ParameterException ex) { cli.getErr().println(ex.getMessage()); if (!UnmatchedArgumentException.printSuggestions(ex, cli.getErr())) { ex.getCommandLine().usage(cli.getErr()); } return new ParseCommandLineArgsResult(cli.getCommandSpec().exitCodeOnInvalidInput()); } catch (Exception ex) { ex.printStackTrace(cli.getErr()); return new ParseCommandLineArgsResult(cli.getCommandSpec().exitCodeOnExecutionException()); } return new ParseCommandLineArgsResult(opts); } Bootstrap(ServerOptions opts); static void main(String[] args);  }
@Test public void testHelp() { final String[] args = new String[]{"-h"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isTrue(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.OK); assertThat(ret.getOptions()).isNull(); }
@Test public void testHelp2() { final String[] args = new String[]{"--help"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isTrue(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.OK); assertThat(ret.getOptions()).isNull(); }
@Test public void testVersion() { final String[] args = new String[]{"-V"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isTrue(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.OK); assertThat(ret.getOptions()).isNull(); }
@Test public void testVersion2() { final String[] args = new String[]{"--version"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isTrue(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.OK); assertThat(ret.getOptions()).isNull(); }
@Test public void testUnknownArgument() { final String[] args = new String[]{"-unknown"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isTrue(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.USAGE); assertThat(ret.getOptions()).isNull(); }
@Test public void testInvalidPort() { String[] args = new String[]{"-p", "wahaha"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isTrue(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.USAGE); assertThat(ret.getOptions()).isNull(); }
@Test public void testInvalidPort2() { String[] args = new String[]{"--port", "wahaha"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isTrue(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.USAGE); assertThat(ret.getOptions()).isNull(); }
@Test public void testInvalidEnableDocService() { String[] args = new String[]{"-d", "wahaha"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isTrue(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.USAGE); assertThat(ret.getOptions()).isNull(); }
@Test public void testArgsInAbbreviationForm() { String[] args = new String[]{"-d", "-c", "path/to/config", "-p", "8080"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isFalse(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.OK); ServerOptions options = ret.getOptions(); assertThat(options).isNotNull(); assertThat(options.docServiceEnabled()).isTrue(); assertThat(options.port()).isEqualTo(8080); assertThat(options.configFilePath()).isEqualTo("path/to/config"); }
@Test public void testArgsInFullForm() { String[] args = new String[]{"--enable-doc-service", "--configuration-file", "path/to/config", "--port", "8080"}; ParseCommandLineArgsResult ret = Bootstrap.parseCommandLineArgs(args); assertThat(ret.isExit()).isFalse(); assertThat(ret.getExitCode()).isEqualTo(ExitCode.OK); ServerOptions options = ret.getOptions(); assertThat(options).isNotNull(); assertThat(options.docServiceEnabled()).isTrue(); assertThat(options.port()).isEqualTo(8080); assertThat(options.configFilePath()).isEqualTo("path/to/config"); }