[homekit] implement basic command completion (#13878)
just the sub-commands. since the show command is already a "search", I didn't feel it's super important to implement on that Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
parent
3e66cd1b33
commit
b56ab10e00
|
@ -17,7 +17,10 @@ import java.util.List;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.io.console.Console;
|
||||
import org.openhab.core.io.console.ConsoleCommandCompleter;
|
||||
import org.openhab.core.io.console.StringsCompleter;
|
||||
import org.openhab.core.io.console.extensions.AbstractConsoleCommandExtension;
|
||||
import org.openhab.core.io.console.extensions.ConsoleCommandExtension;
|
||||
import org.openhab.io.homekit.Homekit;
|
||||
|
@ -43,6 +46,20 @@ public class HomekitCommandExtension extends AbstractConsoleCommandExtension {
|
|||
private static final String SUBCMD_ALLOW_UNAUTHENTICATED = "allowUnauthenticated";
|
||||
private static final String SUBCMD_PRUNE_DUMMY_ACCESSORIES = "pruneDummyAccessories";
|
||||
private static final String SUBCMD_LIST_DUMMY_ACCESSORIES = "listDummyAccessories";
|
||||
private static final StringsCompleter SUBCMD_COMPLETER = new StringsCompleter(
|
||||
List.of(SUBCMD_CLEAR_PAIRINGS, SUBCMD_LIST_ACCESSORIES, SUBCMD_PRINT_ACCESSORY,
|
||||
SUBCMD_ALLOW_UNAUTHENTICATED, SUBCMD_PRUNE_DUMMY_ACCESSORIES, SUBCMD_LIST_DUMMY_ACCESSORIES),
|
||||
false);
|
||||
|
||||
private class CommandCompleter implements ConsoleCommandCompleter {
|
||||
public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List<String> candidates) {
|
||||
if (cursorArgumentIndex == 0) {
|
||||
boolean result = SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates);
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(HomekitCommandExtension.class);
|
||||
|
||||
|
@ -114,6 +131,11 @@ public class HomekitCommandExtension extends AbstractConsoleCommandExtension {
|
|||
this.homekit = homekit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConsoleCommandCompleter getCompleter() {
|
||||
return new CommandCompleter();
|
||||
}
|
||||
|
||||
private void clearHomekitPairings(Console console) {
|
||||
homekit.clearHomekitPairings();
|
||||
console.println("Cleared HomeKit pairings");
|
||||
|
|
Loading…
Reference in New Issue