FileCompleterGenerator { String generateCompleterFile(CommandLineParser<CommandInvocation> command) { StringBuilder out = new StringBuilder(); out.append(generateHeader(command.getProcessedCommand().name())); if(command.isGroupCommand()) out.append(generateArrContains()); out.append(generateMainCompletion(command)); out.append(generateCommand(command)) ; if(command.isGroupCommand()) for(CommandLineParser<CommandInvocation> child : command.getAllChildParsers()) out.append(generateCommand(child)); out.append(generateFooter(command.getProcessedCommand().name())); return out.toString(); }    }
@Test public void testSimpleCommand() { CommandLineParser<CommandInvocation> parser = getParser(TestCommand1.class); FileCompleterGenerator completerGenerator = new FileCompleterGenerator(); String out = completerGenerator.generateCompleterFile(parser); assertTrue(out.contains("_complete_test1")); assertTrue(out.contains("NO_VALUE_OPTIONS=\"--help -h \"")); assertTrue(out.contains("VALUE_OPTIONS=\"--override -o --test -t \"")); }
@Test public void testGroupCommand() { CommandLineParser<CommandInvocation> parser = getParser(GutCommand1.class); FileCompleterGenerator completerGenerator = new FileCompleterGenerator(); String out = completerGenerator.generateCompleterFile(parser); assertTrue(out.contains("_complete_gut")); assertTrue(out.contains("_command_gut")); assertTrue(out.contains("_command_help")); assertTrue(out.contains("_command_rebase")); assertTrue(out.contains("ArrContains")); assertTrue(out.contains("ArrContains COMP_WORDS CHILD0 && { _command_help; return $?; }")); }