MCPcopy Index your code
hub / github.com/remkop/picocli / testUsageNestedSubcommand

Method testUsageNestedSubcommand

src/test/java/picocli/HelpTest.java:2547–2596  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2545 }
2546
2547 @Test
2548 public void testUsageNestedSubcommand() throws IOException {
2549 @Command(name = "main") class MainCommand { @Option(names = "-a") boolean a; @Option(names = "-h", help = true) boolean h;}
2550 @Command(name = "cmd1") class ChildCommand1 { @Option(names = "-b") boolean b; }
2551 @Command(name = "cmd2") class ChildCommand2 { @Option(names = "-c") boolean c; @Option(names = "-h", help = true) boolean h;}
2552 @Command(name = "sub11") class GrandChild1Command1 { @Option(names = "-d") boolean d; }
2553 @Command(name = "sub12") class GrandChild1Command2 { @Option(names = "-e") int e; }
2554 @Command(name = "sub21") class GrandChild2Command1 { @Option(names = "-h", help = true) boolean h; }
2555 @Command(name = "sub22") class GrandChild2Command2 { @Option(names = "-g") boolean g; }
2556 @Command(name = "sub22sub1") class GreatGrandChild2Command2_1 {
2557 @Option(names = "-h", help = true) boolean h;
2558 @Option(names = {"-t", "--type"}) String customType;
2559 }
2560 CommandLine commandLine = new CommandLine(new MainCommand());
2561 commandLine
2562 .addSubcommand("cmd1", new CommandLine(new ChildCommand1())
2563 .addSubcommand("sub11", new GrandChild1Command1())
2564 .addSubcommand("sub12", new GrandChild1Command2())
2565 )
2566 .addSubcommand("cmd2", new CommandLine(new ChildCommand2())
2567 .addSubcommand("sub21", new GrandChild2Command1())
2568 .addSubcommand("sub22", new CommandLine(new GrandChild2Command2())
2569 .addSubcommand("sub22sub1", new GreatGrandChild2Command2_1())
2570 )
2571 );
2572 String main = usageString(commandLine, Help.Ansi.OFF);
2573 assertEquals(String.format("" +
2574 "Usage: main [-ah] [COMMAND]%n" +
2575 " -a%n" +
2576 " -h%n" +
2577 "Commands:%n" +
2578 " cmd1%n" +
2579 " cmd2%n"), main);
2580
2581 String cmd2 = usageString(commandLine.getSubcommands().get("cmd2"), Help.Ansi.OFF);
2582 assertEquals(String.format("" +
2583 "Usage: main cmd2 [-ch] [COMMAND]%n" +
2584 " -c%n" +
2585 " -h%n" +
2586 "Commands:%n" +
2587 " sub21%n" +
2588 " sub22%n"), cmd2);
2589
2590 String sub22 = usageString(commandLine.getSubcommands().get("cmd2").getSubcommands().get("sub22"), Help.Ansi.OFF);
2591 assertEquals(String.format("" +
2592 "Usage: main cmd2 sub22 [-g] [COMMAND]%n" +
2593 " -g%n" +
2594 "Commands:%n" +
2595 " sub22sub1%n"), sub22);
2596 }
2597
2598 @Test
2599 public void testLayoutGetters() {

Callers

nothing calls this directly

Calls 6

addSubcommandMethod · 0.95
getSubcommandsMethod · 0.95
usageStringMethod · 0.80
assertEqualsMethod · 0.80
getMethod · 0.65
formatMethod · 0.45

Tested by

no test coverage detected