/** * Main method. * * @param args Arguments. */ public static void main(String... args) { CommandLine.run(new RootCommand(), System.out, args); } }
public static void main(String[] args) { CommandLine.run(new BenchmarkTool(), args); }
public static void main(String[] args) { CommandLine.run(new FileUtils(), "--directory=examples/src", "list", "-r"); } }
public static void main(String[] args) { if (args.length > 0 && args[0].equals(COMMAND_SOLIDITY)) { args = tail(args); } if (args.length > 0 && args[0].equals(COMMAND_GENERATE)) { args = tail(args); } CommandLine.run(new PicocliRunner(), args); }
@Test public void testHelpSubcommandWithValidCommand() { @Command(subcommands = {Sub.class, HelpCommand.class}) class App implements Runnable{ public void run(){}} ByteArrayOutputStream baos = new ByteArrayOutputStream(); CommandLine.run(new App(), new PrintStream(baos), Help.Ansi.OFF, "help", "sub"); String expected = String.format("" + "Usage: <main class> sub%n" + "This is a subcommand%n"); assertEquals(expected, baos.toString()); }
@Test public void testRunCallsRunnableIfParseSucceeds() { final boolean[] runWasCalled = {false}; @Command class App implements Runnable { public void run() { runWasCalled[0] = true; } } CommandLine.run(new App(), System.err); assertTrue(runWasCalled[0]); }
@Test public void testParentInjectedOnRunWhenConfiguredAsSubcommand() { Top top = new Top(); CommandLine.run(top, System.out, "-d/tmp/blah", "sub", "3"); assertEquals(new File("/tmp/blah"), top.baseDirectory); assertEquals(3 * "/tmp/blah".length(), top.result); } @Test
public static void main(String[] args) { // Since https://github.com/remkop/picocli/issues/491 was fixed in picocli 3.6.0, // Ansi.AUTO is automatically enabled if the AnsiConsole is installed. AnsiConsole.systemInstall(); // Jansi magic CommandLine.run(new WindowsJansiDemo(), System.out, Ansi.AUTO, args); AnsiConsole.systemUninstall(); } }
@Test public void testSubcommandMethodThrowingParameterException() { String expected = String.format("" + "Validation failed%n" + "Usage: maincommand explicit [-v]%n" + " -v%n"); CommandLine.run(new MainCommand(), "explicit", "-v"); assertEquals(expected, this.systemErrRule.getLog()); assertEquals("", this.systemOutRule.getLog()); }
@Test public void testSubcommandMethodInvalidInputHandling() { String expected = String.format("" + "Unknown option: -y%n" + "Usage: maincommand subcommand [-x=<arg0>]%n" + " -x=<arg0>%n"); CommandLine.run(new MainCommand(), "subcommand", "-y"); assertEquals(expected, this.systemErrRule.getLog()); assertEquals("", this.systemOutRule.getLog()); }
@Test public void testRun4WithInvalidInput_ToStdout() { CommandLine.run(new MyRunnable(), System.out, System.out, Help.Ansi.ON, "invalid input"); assertEquals("", systemErrRule.getLog()); assertEquals(INVALID_INPUT + MYCALLABLE_USAGE_ANSI, systemOutRule.getLog()); }
@Test public void testRun1WithHelpRequest() { CommandLine.run(new MyRunnable(), "--help"); assertEquals("", systemErrRule.getLog()); assertEquals(MYCALLABLE_USAGE, systemOutRule.getLog()); }
@Test public void testRun2WithHelpRequest() { CommandLine.run(new MyRunnable(), System.out, "--help"); assertEquals("", systemErrRule.getLog()); assertEquals(MYCALLABLE_USAGE, systemOutRule.getLog()); }
@Test public void testRun4WithHelpRequest() { CommandLine.run(new MyRunnable(), System.out, System.err, Help.Ansi.ON, "--help"); assertEquals("", systemErrRule.getLog()); assertEquals(MYCALLABLE_USAGE_ANSI, systemOutRule.getLog()); }
@Test public void testRun1WithInvalidInput() { CommandLine.run(new MyRunnable(), "invalid input"); assertEquals(MYCALLABLE_INVALID_INPUT, systemErrRule.getLog()); assertEquals("", systemOutRule.getLog()); }
@Test public void testRun2WithInvalidInput() { CommandLine.run(new MyRunnable(), System.out, "invalid input"); assertEquals(MYCALLABLE_INVALID_INPUT, systemErrRule.getLog()); assertEquals("", systemOutRule.getLog()); }
@Test public void testRun3WithHelpRequest() { CommandLine.run(new MyRunnable(), System.out, Help.Ansi.ON, "--help"); assertEquals("", systemErrRule.getLog()); assertEquals(MYCALLABLE_USAGE_ANSI, systemOutRule.getLog()); }
@Test public void testRun3WithInvalidInput() { CommandLine.run(new MyRunnable(), System.out, Help.Ansi.ON, "invalid input"); assertEquals(INVALID_INPUT + MYCALLABLE_USAGE_ANSI, systemErrRule.getLog()); assertEquals("", systemOutRule.getLog()); }
@Test public void testRun4WithHelpRequest_ToCustomStream() { StringPrintStream sps = new StringPrintStream(); CommandLine.run(new MyRunnable(), sps.stream(), System.out, Help.Ansi.ON, "--help"); assertEquals(MYCALLABLE_USAGE_ANSI, sps.toString()); assertEquals("", systemErrRule.getLog()); assertEquals("", systemOutRule.getLog()); }
@Test public void testRun3WithHelpRequest_ToCustomStream() { StringPrintStream sps = new StringPrintStream(); CommandLine.run(new MyRunnable(), sps.stream(), Help.Ansi.ON, "--help"); assertEquals(MYCALLABLE_USAGE_ANSI, sps.toString()); assertEquals("", systemErrRule.getLog()); assertEquals("", systemOutRule.getLog()); }