@Test public void nonsenseUrlGivesError() { ByteArrayOutputStream bout = new ByteArrayOutputStream(); System.setErr(new PrintStream(bout)); CliArgs cliargs = CliArgHelper.parse("--address", "host port"); assertNull("should have failed", cliargs); assertTrue("expected usage: " + bout.toString(), bout.toString().contains("cypher-shell [-h]")); assertTrue("expected error: " + bout.toString(), bout.toString().contains("cypher-shell: error: Failed to parse address")); assertTrue("expected error detail: " + bout.toString(), bout.toString().contains("\n Address should be of the form:")); }
@Nullable public static CliArgs parse(@Nonnull String... args) { final CliArgs cliArgs = new CliArgs(); final ArgumentParser parser = setupParser(cliArgs.getParameters()); final Namespace ns; try { ns = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); return null; } return getCliArgs( cliArgs, parser, ns ); }
CliArgHelper { @Nullable public static CliArgs parse(@Nonnull String... args) { final CliArgs cliArgs = new CliArgs(); final ArgumentParser parser = setupParser(cliArgs.getParameters()); final Namespace ns; try { ns = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); return null; } return getCliArgs( cliArgs, parser, ns ); } }
CliArgHelper { @Nullable public static CliArgs parse(@Nonnull String... args) { final CliArgs cliArgs = new CliArgs(); final ArgumentParser parser = setupParser(cliArgs.getParameters()); final Namespace ns; try { ns = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); return null; } return getCliArgs( cliArgs, parser, ns ); }  }
CliArgHelper { @Nullable public static CliArgs parse(@Nonnull String... args) { final CliArgs cliArgs = new CliArgs(); final ArgumentParser parser = setupParser(cliArgs.getParameters()); final Namespace ns; try { ns = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); return null; } return getCliArgs( cliArgs, parser, ns ); }  @Nullable static CliArgs parse(@Nonnull String... args); static CliArgs parseAndThrow( @Nonnull String... args ); }
CliArgHelper { @Nullable public static CliArgs parse(@Nonnull String... args) { final CliArgs cliArgs = new CliArgs(); final ArgumentParser parser = setupParser(cliArgs.getParameters()); final Namespace ns; try { ns = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); return null; } return getCliArgs( cliArgs, parser, ns ); }  @Nullable static CliArgs parse(@Nonnull String... args); static CliArgs parseAndThrow( @Nonnull String... args );  }