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.input.cache.OnapCommandParameterCache;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
private boolean isInteractiveMode = false;
+ private OnapCommandParameterCache paramCache = new OnapCommandParameterCache();
+
public boolean isInteractiveMode() {
return isInteractiveMode;
}
this.isInteractiveMode = isInteractiveMode;
}
+ public Map<String, String> getParamCache() {
+ return paramCache.getParams(this.getEnabledProductVersion());
+ }
+
+ public void addParamCache(String paramName, String paramValue) {
+ paramCache.add(this.getEnabledProductVersion(), paramName, paramValue);
+ }
+
+ public void removeParamCache(String paramName) {
+ paramCache.remove(this.getEnabledProductVersion(), paramName);
+ }
+
private static OnapCommandRegistrar registrar = null;
/**
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";
+ public static final String PARAM_CACHE_FILE_NAME = "cli.parameter.cache.file";
private Constants() {
}
package org.onap.cli.fw.conf;
-import org.onap.cli.fw.input.OnapCommandParameter;
-
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
return Arrays.stream(prps.getProperty(key).split(",")).map(String::trim).collect(Collectors.toList()); // NOSONAR
}
+ public static String getParamCacheFileName() {
+ return prps.getProperty(Constants.PARAM_CACHE_FILE_NAME);
+ }
}
--- /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.input.cache;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class OnapCommandParameterCache {
+
+ public Map<String, Map<String, String>> paramCache = new HashMap<>();
+
+ public void add(String productVersion, String paramName, String paramValue) {
+
+ if (!paramCache.containsKey(productVersion)) {
+ paramCache.put(productVersion, new HashMap<String, String>());
+ }
+
+ paramCache.get(productVersion).put(paramName, paramValue);
+ }
+
+ public void remove(String productVersion, String paramName) {
+ if (paramCache.containsKey(productVersion)) {
+ if (paramCache.get(productVersion).containsKey(paramName)) {
+ paramCache.get(productVersion).remove(paramName);
+ }
+ }
+ }
+
+ public Map<String, String> getParams(String productVersion) {
+ if (paramCache.containsKey(productVersion)) {
+ return this.paramCache.get(productVersion);
+ } else {
+ return new HashMap<String, String>();
+ }
+ }
+
+ public void persist() {
+ // mrkana add persistence logic
+ }
+
+ public void load() {
+ // mrkanag add loading cache from persistence
+ }
+}
#product version
cli.product.version=cli-1.0
+
+cli.parameter.cache.file=param-cache.json
public class OnapCli {
private List<String> args = new ArrayList<>();
- Map<String, String> paramCache = new HashMap<>();
private int exitCode = -1;
if (args.size() > 1) {
String [] paramEntry = args.get(1).trim().split("=");
if (paramEntry.length >= 2) {
- this.paramCache.put(paramEntry[0].trim(), paramEntry[1].trim());
+ OnapCommandRegistrar.getRegistrar().addParamCache(paramEntry[0].trim(), paramEntry[1].trim());
} else {
this.print("Please use it in the form of 'set param-name=param-value'");
}
} else {
- this.print(this.paramCache.toString());
+ this.print(OnapCommandRegistrar.getRegistrar().getParamCache().toString());
}
} else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_UNSET)) {
if (args.size() > 1) {
for (int i = 1; i <args.size(); i++) {
- if (this.paramCache.containsKey(args.get(i))) {
- this.paramCache.remove(args.get(i));
- }
+ OnapCommandRegistrar.getRegistrar().removeParamCache(args.get(i));
}
}
} else {
}
for (OnapCommandParameter param: cmd.getParameters()) {
- if (this.paramCache.containsKey(param.getLongOption())) {
- param.setValue(this.paramCache.get(param.getLongOption()));
+ if (OnapCommandRegistrar.getRegistrar().getParamCache().containsKey(param.getLongOption())) {
+ param.setValue(OnapCommandRegistrar.getRegistrar().getParamCache().get(param.getLongOption()));
}
}