From 50d946e467162c5e224d3ddbe6fdb8c050fe6f58 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 24 Oct 2022 23:34:32 +0200 Subject: [PATCH] [netatmo] Console command completion (#13587) Signed-off-by: Laurent Garnier --- .../console/NetatmoCommandExtension.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/console/NetatmoCommandExtension.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/console/NetatmoCommandExtension.java index b8b28bef7..d2e35fdcb 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/console/NetatmoCommandExtension.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/console/NetatmoCommandExtension.java @@ -23,6 +23,8 @@ import org.openhab.binding.netatmo.internal.api.data.ModuleType; import org.openhab.binding.netatmo.internal.api.dto.NAModule; import org.openhab.binding.netatmo.internal.handler.ApiBridgeHandler; 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.core.thing.Thing; @@ -41,9 +43,10 @@ import org.osgi.service.component.annotations.Reference; @NonNullByDefault @Component(service = ConsoleCommandExtension.class) -public class NetatmoCommandExtension extends AbstractConsoleCommandExtension { +public class NetatmoCommandExtension extends AbstractConsoleCommandExtension implements ConsoleCommandCompleter { private static final String SHOW_IDS = "showIds"; + private static final StringsCompleter SUBCMD_COMPLETER = new StringsCompleter(List.of(SHOW_IDS), false); private final ThingRegistry thingRegistry; private @Nullable Console console; @@ -94,4 +97,17 @@ public class NetatmoCommandExtension extends AbstractConsoleCommandExtension { public List getUsages() { return Arrays.asList(buildCommandUsage(SHOW_IDS, "list all devices and modules ids")); } + + @Override + public @Nullable ConsoleCommandCompleter getCompleter() { + return this; + } + + @Override + public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List candidates) { + if (cursorArgumentIndex <= 0) { + return SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates); + } + return false; + } }