Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/picocli/AutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -260,7 +261,7 @@ private static String bashify(CharSequence value) {
char c = value.charAt(i);
if (Character.isLetterOrDigit(c) || c == '_') {
builder.append(c);
} else if (Character.isSpaceChar(c)) {
} else if (Character.isSpaceChar(c) || c == '-') {
builder.append('_');
}
}
Expand Down Expand Up @@ -549,11 +550,20 @@ private static List<CommandDescriptor> createHierarchy(String scriptName, Comman

private static void createSubHierarchy(String scriptName, String parentWithoutTopLevelCommand, CommandLine commandLine, List<CommandDescriptor> out) {
// breadth-first: generate command lists and function calls for predecessors + each subcommand
Map<String, Integer> functionAliasCounts = new HashMap<String, Integer>();
for (Map.Entry<String, CommandLine> entry : commandLine.getSubcommands().entrySet()) {
CommandSpec spec = entry.getValue().getCommandSpec();
if (spec.usageMessage().hidden()) { continue; } // #887 skip hidden subcommands
String commandName = entry.getKey(); // may be an alias
String functionNameWithoutPrefix = bashify(concat("_", parentWithoutTopLevelCommand.replace(' ', '_'), commandName));
Integer functionAliasCount = functionAliasCounts.get(functionNameWithoutPrefix);
if (functionAliasCount == null) {
functionAliasCount = 0;
}
functionAliasCounts.put(functionNameWithoutPrefix, functionAliasCount + 1);
if (functionAliasCount > 0) {
functionNameWithoutPrefix = concat("_", functionNameWithoutPrefix, "alias", String.valueOf(functionAliasCount));
}
String functionName = concat("_", "_picocli", scriptName, functionNameWithoutPrefix);
String parentFunctionName = parentWithoutTopLevelCommand.length() == 0
? concat("_", "_picocli", scriptName)
Expand Down