@Test public void testIsUsageHelpRequested_initiallyFalse() { @Command(mixinStandardHelpOptions = true) class App { @Option(names = "-x") String x; } CommandLine cmd = new CommandLine(new App()); assertFalse(cmd.isUsageHelpRequested()); }
for (int i = 0; i < parsedCommands.size(); i++) { CommandLine parsed = parsedCommands.get(i); if (parsed.isUsageHelpRequested()) { parsed.usage(out, colorScheme); return true;
@Test public void testAutoHelpMixinUsageHelpOption() { @Command(mixinStandardHelpOptions = true) class App {} String[] helpOptions = {"-h", "--help"}; for (String option : helpOptions) { List<CommandLine> list = new CommandLine(new App()).parse(option); assertTrue(list.get(0).isUsageHelpRequested()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream out = new PrintStream(baos); assertTrue(CommandLine.printHelpIfRequested(list, out, out, Help.Ansi.OFF)); String expected = String.format("" + "Usage: <main class> [-hV]%n" + " -h, --help Show this help message and exit.%n" + " -V, --version Print version information and exit.%n"); assertEquals(expected, baos.toString()); } }
@Test public void testCommandLine_isUsageHelpRequested_falseWhenNotSpecified() { List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--version"); assertFalse("usage help requested", parsedCommands.get(0).isUsageHelpRequested()); } @Test
@Test public void testCommandLine_isUsageHelpRequested_trueWhenSpecified() { List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--help"); assertTrue("usage help requested", parsedCommands.get(0).isUsageHelpRequested()); } @Test
if (parsed.isUsageHelpRequested()) { return printHelpMessage(parsed, System.out);
private boolean isHelpRequested(List<CommandLine> commands) { for (CommandLine command : commands) if (command.isUsageHelpRequested() || command.isVersionHelpRequested()) return true; return false; } }
if ( commandLine.isUsageHelpRequested() ) { commandLine.usage( System.out ); System.exit( 0 );
CommandLine commandLine = new CommandLine(cliArgs); commandLine.parse(args); if (commandLine.isUsageHelpRequested()) { commandLine.usage(System.out); return;
if ( commandLine.isUsageHelpRequested() ) { commandLine.usage( System.out ); System.exit( 0 );
@Test public void testIsUsageHelpRequested_initiallyFalse() { @Command(mixinStandardHelpOptions = true) class App { @Option(names = "-x") String x; } CommandLine cmd = new CommandLine(new App()); assertFalse(cmd.isUsageHelpRequested()); }
for (int i = 0; i < parsedCommands.size(); i++) { CommandLine parsed = parsedCommands.get(i); if (parsed.isUsageHelpRequested()) { parsed.usage(out, colorScheme); return true;
@Test public void testAutoHelpMixinUsageHelpOption() { @Command(mixinStandardHelpOptions = true) class App {} String[] helpOptions = {"-h", "--help"}; for (String option : helpOptions) { List<CommandLine> list = new CommandLine(new App()).parse(option); assertTrue(list.get(0).isUsageHelpRequested()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream out = new PrintStream(baos); assertTrue(CommandLine.printHelpIfRequested(list, out, out, Help.Ansi.OFF)); String expected = String.format("" + "Usage: <main class> [-hV]%n" + " -h, --help Show this help message and exit.%n" + " -V, --version Print version information and exit.%n"); assertEquals(expected, baos.toString()); } }
@Test public void testCommandLine_isUsageHelpRequested_trueWhenSpecified() { List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--help"); assertTrue("usage help requested", parsedCommands.get(0).isUsageHelpRequested()); } @Test
@Test public void testCommandLine_isUsageHelpRequested_falseWhenNotSpecified() { List<CommandLine> parsedCommands = new CommandLine(new RequiredField()).parse("--version"); assertFalse("usage help requested", parsedCommands.get(0).isUsageHelpRequested()); } @Test
if (cli.isUsageHelpRequested()) { CommandLine.usage(new Options(), normal); return 3;
if (parsed.isUsageHelpRequested()) { return printHelpMessage(parsed, System.out);