From 2cf4b3ef2af8c5f1d1591899923a18961c5ef990 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Wed, 30 Aug 2017 17:58:56 +0530 Subject: Add command use use command helps to choose the product version to use while there are more than one product commands present in cli CLI-37 Change-Id: I4020bbbcc7574cfcc73ddcd4d46c627087990d20 Signed-off-by: Kanagaraj Manickam k00365106 --- main/src/main/java/org/onap/cli/main/OnapCli.java | 25 +++++++++++++++++++++- .../org/onap/cli/main/conf/OnapCliConstants.java | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'main') diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java index 2695c3f7..528c3e18 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -119,8 +119,10 @@ public class OnapCli { */ public void handleInteractive() { // NOSONAR if (isInteractive()) { + ConsoleReader console = null; try { + OnapCommandRegistrar.getRegistrar().setInteractiveMode(true); console = createConsoleReader(); String line = null; while ((line = console.readLine()) != null) { @@ -132,10 +134,30 @@ public class OnapCli { continue; } this.args = Arrays.asList(line.split(OnapCliConstants.PARAM_INTERACTIVE_ARG_SPLIT_PATTERN)); + + if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_USE)) { + if (args.size() == 1) { + this.print("Please input the product version to use, supported versions: " + + OnapCommandRegistrar.getRegistrar().getAvailableProductVersions()); + } else { + try { + OnapCommandRegistrar.getRegistrar().setEnabledProductVersion(args.get(1)); + console.close(); + console = createConsoleReader(); + } catch (OnapCommandException e) { + this.print(e); + } + } + + continue; + } handleCommand(); } } catch (IOException e) { // NOSONAR this.print("Failed to read console, " + e.getMessage()); + } catch (OnapCommandException e) { + this.print(e); + this.exitFailure(); } finally { try { TerminalFactory.get().restore(); @@ -175,7 +197,8 @@ public class OnapCli { try { StringCompleter strCompleter = new StringCompleter(OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion()); strCompleter.add(OnapCliConstants.PARAM_INTERACTIVE_EXIT, - OnapCliConstants.PARAM_INTERACTIVE_CLEAR); + OnapCliConstants.PARAM_INTERACTIVE_CLEAR, + OnapCliConstants.PARAM_INTERACTIVE_USE); console.addCompleter(strCompleter); console.setPrompt(OnapCliConstants.PARAM_INTERACTIVE_PROMPT); } catch (OnapCommandException e) { // NOSONAR diff --git a/main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java b/main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java index 7fb51cbe..4db26f74 100644 --- a/main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java +++ b/main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java @@ -33,6 +33,7 @@ public final class OnapCliConstants { public static final String PARAM_INTERACTIVE_EXIT = "exit"; public static final String PARAM_INTERACTIVE_BYE = "bye"; public static final String PARAM_INTERACTIVE_CLEAR = "clear"; + public static final String PARAM_INTERACTIVE_USE = "use"; public static final String PARAM_INTERACTIVE_ARG_SPLIT_PATTERN = "\\s+"; private OnapCliConstants(){} -- cgit 1.2.3-korg