summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java20
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandProductVersionInvalid.java32
-rw-r--r--framework/src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand2
-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
6 files changed, 77 insertions, 4 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
index 56f04e16..39f684cc 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
@@ -31,6 +31,7 @@ import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
import org.onap.cli.fw.error.OnapCommandInvalidRegistration;
import org.onap.cli.fw.error.OnapCommandNotFound;
+import org.onap.cli.fw.error.OnapCommandProductVersionInvalid;
import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
import org.onap.cli.fw.error.OnapCommandRegistrationVersionMissing;
import org.onap.cli.fw.output.OnapCommandResult;
@@ -54,6 +55,16 @@ public class OnapCommandRegistrar {
private String enabledProductVersion = OnapCommandConfg.getEnabledProductVersion();
+ private boolean isInteractiveMode = false;
+
+ public boolean isInteractiveMode() {
+ return isInteractiveMode;
+ }
+
+ public void setInteractiveMode(boolean isInteractiveMode) {
+ this.isInteractiveMode = isInteractiveMode;
+ }
+
private static OnapCommandRegistrar registrar = null;
/**
@@ -126,7 +137,11 @@ public class OnapCommandRegistrar {
return this.availableProductVersions;
}
- public void setEnabledProductVersion(String version) {
+ public void setEnabledProductVersion(String version) throws OnapCommandProductVersionInvalid {
+ if (!this.availableProductVersions.contains(version)) {
+ throw new OnapCommandProductVersionInvalid(version, availableProductVersions);
+ }
+
this.enabledProductVersion = version;
}
@@ -225,7 +240,8 @@ public class OnapCommandRegistrar {
String errorNote = "";
if (!this.availableProductVersions.contains(configuredProductVersion)) {
errorNote = "** CUATION: Please configure the enabled product version to use one of " + this.availableProductVersions.toString() +
- ".\nTo enable a product version, set env variable CLI_PRODUCT_VERSION or cli.product.version in onap.properties";
+ ".\nTo enable a product version, use one of following methods:\n\t 1. set env variable CLI_PRODUCT_VERSION"
+ + "\n\t 2. set cli.product.version in onap.properties \n\t 3. in interactive mode, use the directive 'use <product version>'";
}
return "CLI version : " + version + "\n"
+ "Available product versions: " + this.availableProductVersions.toString() + "\n"
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
index 980b94d3..d27649b0 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
@@ -192,6 +192,7 @@ public class Constants {
public static final String HTTP_SUCCESS_CODE_INVALID = "Invalid http success code.";
public static final String HTTP_SAMPLE_RESPONSE_EMPTY = "Sample response cann't be null or empty";
public static final String HTTP_SAMPLE_RESPONSE_FAILED_PARSING = "The http Sample response json is failed to parse.";
+ public static final String USE_DIRECTIVE = "use";
private Constants() {
}
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandProductVersionInvalid.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandProductVersionInvalid.java
new file mode 100644
index 00000000..7ec69e6b
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandProductVersionInvalid.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.cli.fw.error;
+
+import java.util.Set;
+
+/**
+ * ONAP command product version is invalid
+ *
+ */
+public class OnapCommandProductVersionInvalid extends OnapCommandException {
+
+ private static final long serialVersionUID = 5513297861129088463L;
+
+ public OnapCommandProductVersionInvalid(String invalidVersion, Set<String> validVersions) {
+ super("0x0031", "Given product version " + invalidVersion + " is invalid. Please use one of " + validVersions);
+ }
+}
diff --git a/framework/src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand b/framework/src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand
index 89648bf5..422da568 100644
--- a/framework/src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand
+++ b/framework/src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand
@@ -1,2 +1,2 @@
org.onap.cli.fw.cmd.OnapSchemaValidateCommand
-org.onap.cli.fw.cmd.OnapSchemaRefreshCommand \ No newline at end of file
+org.onap.cli.fw.cmd.OnapSchemaRefreshCommand
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(){}