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;
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;
/**
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;
}
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"
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() {
}
--- /dev/null
+/*
+ * 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);
+ }
+}
org.onap.cli.fw.cmd.OnapSchemaValidateCommand
-org.onap.cli.fw.cmd.OnapSchemaRefreshCommand
\ No newline at end of file
+org.onap.cli.fw.cmd.OnapSchemaRefreshCommand
*/
public void handleInteractive() { // NOSONAR
if (isInteractive()) {
+
ConsoleReader console = null;
try {
+ OnapCommandRegistrar.getRegistrar().setInteractiveMode(true);
console = createConsoleReader();
String line = null;
while ((line = console.readLine()) != null) {
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();
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
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(){}