@Test public void testIsVersionHelpRequested_initiallyFalse() { @Command(mixinStandardHelpOptions = true) class App { @Option(names = "-x") String x; } CommandLine cmd = new CommandLine(new App()); assertFalse(cmd.isVersionHelpRequested()); }
@Test public void testAutoHelpMixinVersionHelpOption() { @Command(mixinStandardHelpOptions = true, version = "1.2.3") class App {} String[] versionOptions = {"-V", "--version"}; for (String option : versionOptions) { List<CommandLine> list = new CommandLine(new App()).parse(option); assertTrue(list.get(0).isVersionHelpRequested()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream out = new PrintStream(baos); assertTrue(CommandLine.printHelpIfRequested(list, out, out, Help.Ansi.OFF)); String expected = String.format("1.2.3%n"); assertEquals(expected, baos.toString()); } }
parsed.usage(out, colorScheme); return true; } else if (parsed.isVersionHelpRequested()) { parsed.printVersionHelp(out, colorScheme.ansi); return true;
@Test public void testCommandLine_isVersionHelpRequested_trueWhenSpecified() { List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--version"); assertTrue("version info requested", parsedCommands.get(0).isVersionHelpRequested()); } @Test
@Test public void testCommandLine_isVersionHelpRequested_falseWhenNotSpecified() { List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--help"); assertFalse("version info requested", parsedCommands.get(0).isVersionHelpRequested()); } @Test
return printHelpMessage(parsed, System.out); if (parsed.isVersionHelpRequested()) { return printVersionHelpMessage(parsed);
private boolean isHelpRequested(List<CommandLine> commands) { for (CommandLine command : commands) if (command.isUsageHelpRequested() || command.isVersionHelpRequested()) return true; return false; } }
System.exit( 0 ); if ( commandLine.isVersionHelpRequested() ) { commandLine.printVersionHelp( System.out ); System.exit( 0 );
@Test public void testIsVersionHelpRequested_initiallyFalse() { @Command(mixinStandardHelpOptions = true) class App { @Option(names = "-x") String x; } CommandLine cmd = new CommandLine(new App()); assertFalse(cmd.isVersionHelpRequested()); }
@Test public void testAutoHelpMixinVersionHelpOption() { @Command(mixinStandardHelpOptions = true, version = "1.2.3") class App {} String[] versionOptions = {"-V", "--version"}; for (String option : versionOptions) { List<CommandLine> list = new CommandLine(new App()).parse(option); assertTrue(list.get(0).isVersionHelpRequested()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream out = new PrintStream(baos); assertTrue(CommandLine.printHelpIfRequested(list, out, out, Help.Ansi.OFF)); String expected = String.format("1.2.3%n"); assertEquals(expected, baos.toString()); } }
parsed.usage(out, colorScheme); return true; } else if (parsed.isVersionHelpRequested()) { parsed.printVersionHelp(out, colorScheme.ansi); return true;
@Test public void testCommandLine_isVersionHelpRequested_falseWhenNotSpecified() { List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--help"); assertFalse("version info requested", parsedCommands.get(0).isVersionHelpRequested()); } @Test
@Test public void testCommandLine_isVersionHelpRequested_trueWhenSpecified() { List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--version"); assertTrue("version info requested", parsedCommands.get(0).isVersionHelpRequested()); } @Test
if (cli.isVersionHelpRequested()) { new CommandLine(new Options()).printVersionHelp( normal,
return printHelpMessage(parsed, System.out); if (parsed.isVersionHelpRequested()) { return printVersionHelpMessage(parsed);