diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/src/main/java/org/onap/cli/main/OnapCli.java | 25 | ||||
-rw-r--r-- | main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java | 1 |
2 files changed, 25 insertions, 1 deletions
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(){} |