FlagsModuleBuilder { public final Module build(final String... args) { logger.info("Command line: {}", Joiner.on(" ").join(args)); return new Module() { @Override public void configure(Binder binder) { JCommander jcommander = new JCommander(); jcommander.addObject(modules); HelpFlag helpFlag = new HelpFlag(); jcommander.addObject(helpFlag); ParameterException parameterException = null; try { jcommander.parse(args); } catch (ParameterException e) { logger.error("Error parsing command line", e); parameterException = e; } if (parameterException != null || helpFlag.help) { jcommander.usage(); throw parameterException == null ? new HelpException() : parameterException; } for (Module module : modules) { binder.install(module); } } }; }  final FlagsModuleBuilder addModule(Module module); final FlagsModuleBuilder addModules(Iterable<Module> modules); final Module build(final String... args);  }
@Test public void testBadParam() throws Exception { try { Guice.createInjector(Stage.DEVELOPMENT, new FlagsModuleBuilder().build("--bad-parameter")); } catch (CreationException e) { assertTrue(e.getCause() instanceof ParameterException); } }
@Test public void testHelpParam() throws Exception { try { new FlagsModuleBuilder().build("--help"); } catch (CreationException e) { assertTrue(e.getCause() instanceof ParameterException); } }