try { final ParseResult parseResult = commandLine.parseArgs(args); if (parseResult.isVersionHelpRequested()) { System.out.println(getVersionString());
assertFalse(result.hasSubcommand()); assertFalse(result.isUsageHelpRequested()); assertFalse(result.isVersionHelpRequested());
@Test public void testIsUsageHelpRequested() { @Command(mixinStandardHelpOptions = true) class App { @Option(names = "-x") String x; } CommandLine cmd = new CommandLine(new App()); ParseResult parseResult = cmd.parseArgs("-h"); assertTrue(parseResult.isUsageHelpRequested()); assertFalse(parseResult.isVersionHelpRequested()); assertSame(cmd.getCommandSpec().optionsMap().get("-h"), parseResult.matchedOption('h')); assertTrue(parseResult.unmatched().isEmpty()); assertTrue(parseResult.matchedPositionals().isEmpty()); }
try { final ParseResult parseResult = commandLine.parseArgs(args); if (parseResult.isVersionHelpRequested()) { System.out.println(getVersionString());
assertFalse(result.hasSubcommand()); assertFalse(result.isUsageHelpRequested()); assertFalse(result.isVersionHelpRequested());
@Test public void testBasicUsage() { class App { @Option(names = {"-t", "-ttt"}) boolean boolVal; @Option(names = {"-i", "-int"}) int intVal; @Parameters String[] positional; } ParseResult result = new CommandLine(new App()).parseArgs("-t", "-i", "1", "a", "b"); assertEquals(Arrays.asList("-t", "-i", "1", "a", "b"), result.originalArgs()); assertSame(result.commandSpec().findOption("-t"), result.tentativeMatch.get(0)); assertSame(result.commandSpec().findOption("-i"), result.tentativeMatch.get(1)); assertSame(result.originalArgs().get(2), result.tentativeMatch.get(2)); assertSame(result.commandSpec().positionalParameters().get(0), result.tentativeMatch.get(3)); assertSame(result.commandSpec().positionalParameters().get(0), result.tentativeMatch.get(4)); assertTrue(result.unmatched().isEmpty()); assertFalse(result.hasSubcommand()); assertFalse(result.isUsageHelpRequested()); assertFalse(result.isVersionHelpRequested()); assertTrue(result.hasMatchedOption("-ttt")); assertTrue(result.hasMatchedOption("-t")); assertTrue(result.hasMatchedOption("-i")); assertTrue(result.hasMatchedOption("-int")); assertFalse(result.hasMatchedOption("-unknown")); assertTrue(result.hasMatchedPositional(0)); assertTrue(result.hasMatchedPositional(1)); } @Test
@Test public void testIsUsageHelpRequested() { @Command(mixinStandardHelpOptions = true) class App { @Option(names = "-x") String x; } CommandLine cmd = new CommandLine(new App()); ParseResult parseResult = cmd.parseArgs("-h"); assertTrue(parseResult.isUsageHelpRequested()); assertFalse(parseResult.isVersionHelpRequested()); assertSame(cmd.getCommandSpec().optionsMap().get("-h"), parseResult.matchedOption('h')); assertTrue(parseResult.unmatched().isEmpty()); assertTrue(parseResult.matchedPositionals().isEmpty()); }
@Test public void testIsVersionHelpRequested() { @Command(mixinStandardHelpOptions = true) class App { @Option(names = "-x") String x; } CommandLine cmd = new CommandLine(new App()); ParseResult parseResult = cmd.parseArgs("--version"); assertFalse(parseResult.isUsageHelpRequested()); assertTrue(parseResult.isVersionHelpRequested()); assertSame(cmd.getCommandSpec().optionsMap().get("--version"), parseResult.matchedOption('V')); }
@Test public void testBooleanObjectVersionHelpOptions() { CommandSpec cmd = CommandSpec.create().add(OptionSpec.builder("-x").type(Boolean.class).versionHelp(true).build()); assertTrue(new CommandLine(cmd).parseArgs("-x").isVersionHelpRequested()); }
@Test public void testBasicUsage() { class App { @Option(names = {"-t", "-ttt"}) boolean boolVal; @Option(names = {"-i", "-int"}) int intVal; @Parameters String[] positional; } ParseResult result = new CommandLine(new App()).parseArgs("-t", "-i", "1", "a", "b"); assertEquals(Arrays.asList("-t", "-i", "1", "a", "b"), result.originalArgs()); assertSame(result.commandSpec().findOption("-t"), result.tentativeMatch.get(0)); assertSame(result.commandSpec().findOption("-i"), result.tentativeMatch.get(1)); assertSame(result.originalArgs().get(2), result.tentativeMatch.get(2)); assertSame(result.commandSpec().positionalParameters().get(0), result.tentativeMatch.get(3)); assertSame(result.commandSpec().positionalParameters().get(0), result.tentativeMatch.get(4)); assertTrue(result.unmatched().isEmpty()); assertFalse(result.hasSubcommand()); assertFalse(result.isUsageHelpRequested()); assertFalse(result.isVersionHelpRequested()); assertTrue(result.hasMatchedOption("-ttt")); assertTrue(result.hasMatchedOption("-t")); assertTrue(result.hasMatchedOption("-i")); assertTrue(result.hasMatchedOption("-int")); assertFalse(result.hasMatchedOption("-unknown")); assertTrue(result.hasMatchedPositional(0)); assertTrue(result.hasMatchedPositional(1)); } @Test
@Test public void testIsVersionHelpRequested() { @Command(mixinStandardHelpOptions = true) class App { @Option(names = "-x") String x; } CommandLine cmd = new CommandLine(new App()); ParseResult parseResult = cmd.parseArgs("--version"); assertFalse(parseResult.isUsageHelpRequested()); assertTrue(parseResult.isVersionHelpRequested()); assertSame(cmd.getCommandSpec().optionsMap().get("--version"), parseResult.matchedOption('V')); }
@Test public void testBooleanObjectVersionHelpOptions() { CommandSpec cmd = CommandSpec.create().add(OptionSpec.builder("-x").type(Boolean.class).versionHelp(true).build()); assertTrue(new CommandLine(cmd).parseArgs("-x").isVersionHelpRequested()); }