generateFunctionCallsToArrContains(scriptName, predecessors, commandLine, buff, functionCallsToArrContains, function2command);
private static void generateFunctionCallsToArrContains(String scriptName, List<String> predecessors, CommandLine commandLine, StringBuilder buff, List<String> functionCalls, Map<CommandDescriptor, CommandLine> function2command) { // breadth-first: generate command lists and function calls for predecessors + each subcommand for (Map.Entry<String, CommandLine> entry : commandLine.getSubcommands().entrySet()) { int count = functionCalls.size(); String functionName = "_picocli_" + scriptName + "_" + concat("_", predecessors, entry.getKey(), new Bashify()); functionCalls.add(format(" ArrContains COMP_WORDS CMDS%2$d && { %1$s; return $?; }\n", functionName, count)); buff.append( format(" CMDS%2$d=(%1$s)\n", concat(" ", predecessors, entry.getKey(), new NullFunction()), count)); // remember the function name and associated subcommand so we can easily generate a function later function2command.put(new CommandDescriptor(functionName, entry.getKey()), entry.getValue()); } // then recursively do the same for all nested subcommands for (Map.Entry<String, CommandLine> entry : commandLine.getSubcommands().entrySet()) { predecessors.add(entry.getKey()); generateFunctionCallsToArrContains(scriptName, predecessors, entry.getValue(), buff, functionCalls, function2command); predecessors.remove(predecessors.size() - 1); } } private static String concat(String infix, String... values) {
generateFunctionCallsToArrContains(scriptName, predecessors, commandLine, buff, functionCallsToArrContains, function2command);
private static void generateFunctionCallsToArrContains(String scriptName, List<String> predecessors, CommandLine commandLine, StringBuilder buff, List<String> functionCalls, Map<CommandDescriptor, CommandLine> function2command) { // breadth-first: generate command lists and function calls for predecessors + each subcommand for (Map.Entry<String, CommandLine> entry : commandLine.getSubcommands().entrySet()) { int count = functionCalls.size(); String functionName = "_picocli_" + scriptName + "_" + concat("_", predecessors, entry.getKey(), new Bashify()); functionCalls.add(format(" ArrContains COMP_WORDS CMDS%2$d && { %1$s; return $?; }\n", functionName, count)); buff.append( format(" CMDS%2$d=(%1$s)\n", concat(" ", predecessors, entry.getKey(), new NullFunction()), count)); // remember the function name and associated subcommand so we can easily generate a function later function2command.put(new CommandDescriptor(functionName, entry.getKey()), entry.getValue()); } // then recursively do the same for all nested subcommands for (Map.Entry<String, CommandLine> entry : commandLine.getSubcommands().entrySet()) { predecessors.add(entry.getKey()); generateFunctionCallsToArrContains(scriptName, predecessors, entry.getValue(), buff, functionCalls, function2command); predecessors.remove(predecessors.size() - 1); } } private static String concat(String infix, String... values) {