summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-08-30 17:58:56 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-08-31 10:56:58 +0530
commit2cf4b3ef2af8c5f1d1591899923a18961c5ef990 (patch)
treedb3627f1ed67ccdb2c55f5c59c24bac2bde60748 /main
parentf548d5e40b755bc9f6537dae66c161d2f0262b17 (diff)
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 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java25
-rw-r--r--main/src/main/java/org/onap/cli/main/conf/OnapCliConstants.java1
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(){}