Skip to content

Commit

Permalink
Fix logical fault of possibly replacing other command names
Browse files Browse the repository at this point in the history
  • Loading branch information
NewbieOrange committed Sep 20, 2021
1 parent 06eddec commit b52b1c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/java/picocli/AutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ private static void generateFunctionCallsToArrContains(StringBuilder buff,
int count = functionCalls.size();
CommandSpec spec = descriptor.commandLine.getCommandSpec();
String full = spec.qualifiedName(" ");
String withoutTopLevelCommand = full.substring(spec.root().name().length() + 1).replace(spec.name(), descriptor.commandName);
String withoutTopLevelCommand = full.substring(spec.root().name().length() + 1,
full.length() - spec.name().length()) + descriptor.commandName;

functionCalls.add(format(" if CompWordsContainsArray \"${cmds%2$d[@]}\"; then %1$s; return $?; fi\n", descriptor.functionName, count));
buff.append( format(" local cmds%2$d=(%1$s)\n", withoutTopLevelCommand, count));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6412,7 +6412,7 @@ public CommandSpec addSubcommand(String name, CommandSpec subcommand) {
*/
public CommandSpec addSubcommand(String name, CommandLine subCommandLine) {
CommandSpec subSpec = subCommandLine.getCommandSpec();
String actualName = interpolator.interpolateCommandName(validateSubcommandName(name, subSpec));
String actualName = validateSubcommandName(interpolator.interpolateCommandName(name), subSpec);
Tracer t = new Tracer();
if (t.isDebug()) {t.debug("Adding subcommand '%s' to '%s'%n", actualName, this.qualifiedName());}
String previousName = commands.getCaseSensitiveKey(actualName);
Expand Down

0 comments on commit b52b1c3

Please sign in to comment.