diff options
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/main/java/org/onap/cli/main/OnapCli.java | 22 | ||||
-rw-r--r-- | main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java | 19 |
2 files changed, 20 insertions, 21 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 4d7e97af..ee9c7b33 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -238,7 +238,7 @@ public class OnapCli { * Handles batch command. --param-file */ public void handleBatchCommand() { - try { + try { //NOSONAR if (this.paramFile != null) { //Read YAML and loop thru it // one @@ -382,22 +382,18 @@ public class OnapCli { this.args = new ArrayList<>(); this.args.addAll(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 use it in the form of use <product-version>.\nSupported versions: " + - OnapCommandRegistrar.getRegistrar().getAvailableProductVersions()); - } else { - try { + if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_USE)) { + if (args.size() == 1) { + this.print("Please use it in the form of use <product-version>.\nSupported versions: " + + OnapCommandRegistrar.getRegistrar().getAvailableProductVersions()); + } else { OnapCommandRegistrar.getRegistrar().setEnabledProductVersion(args.get(1)); console = createConsoleReader(); - } catch (OnapCommandException e) { - this.print(e); } - } - } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_HELP)) { - this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion()); - this.print(OnapCli.getDirectiveHelp()); + } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_HELP)) { + this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion()); + this.print(OnapCli.getDirectiveHelp()); } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_VERSION)) { this.printVersion = true; handleVersion(); diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java index d0885def..174dfd2a 100644 --- a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java +++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java @@ -99,7 +99,8 @@ public class OnapCliArgsParser { } int positionalIdx = 0; - for (int i = 0; i < args.size(); i++) { + int i = 0; + while ( i < args.size()) { String paramName = null; if (shortOptionMap.containsKey(args.get(i))) { paramName = shortOptionMap.get(args.get(i)); @@ -112,6 +113,7 @@ public class OnapCliArgsParser { if ((i + 1) == args.size() || args.get(i + 1).startsWith("-")) { if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.BOOL)) { paramMap.get(paramName).setValue(true); + i+=2; continue; } throw new OnapCliArgumentValueMissing(args.get(i)); @@ -120,26 +122,26 @@ public class OnapCliArgsParser { if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.JSON)) { paramMap.get(paramName).setValue(readJsonStringFromUrl(args.get(i + 1), paramMap.get(paramName).getName())); - i++; + i+=2; continue; } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.TEXT)) { paramMap.get(paramName).setValue(readTextStringFromUrl(args.get(i + 1), paramMap.get(paramName).getName())); - i++; + i+=2; continue; } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.YAML)) { String value = readYamlStringFromUrl(args.get(i + 1), paramMap.get(paramName).getName()); paramMap.get(paramName).setValue(value); - i++; + i+=2; continue; } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.BYTE)) { paramMap.get(paramName).setValue(readBytesFromUrl(args.get(i + 1), paramMap.get(paramName).getName())); - i++; + i+=2; continue; } else if (paramMap.get(paramName).getParameterType() @@ -149,7 +151,7 @@ public class OnapCliArgsParser { list.add(readTextStringFromUrl(args.get(i + 1), paramMap.get(paramName).getName())); paramMap.get(paramName).setValue(list); - i++; + i+=2; continue; } else if (paramMap.get(paramName).getParameterType() @@ -171,13 +173,13 @@ public class OnapCliArgsParser { //map.put(argArr[0], readTextStringFromUrl(argArr[1], paramMap.get(paramName).getName())); map.put(argArr[0], argArr[1]); paramMap.get(paramName).setValue(map); - i++; + i+=2; continue; } paramMap.get(paramName).setValue(args.get(i + 1)); - i++; + i+=2; continue; } @@ -191,6 +193,7 @@ public class OnapCliArgsParser { paramMap.get(positionArgs.get(positionalIdx)).setValue(args.get(i)); positionalIdx++; + i+=2; } params.clear(); |