From b4723e06648181934eacec04fa987811a0b6f959 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Fri, 9 Mar 2018 02:52:49 +0530 Subject: Improve map input parsing Issue-ID: CLI-99 Change-Id: Ie78b3567d4542b8ea59d62b94d48a4351e803a5c Signed-off-by: Kanagaraj Manickam k00365106 --- .../java/org/onap/cli/main/utils/OnapCliArgsParser.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'main') 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 16d6a285..906d8d11 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 @@ -116,11 +116,13 @@ public class OnapCliArgsParser { paramMap.get(paramName).getName())); i++; continue; + } if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.TEXT)) { paramMap.get(paramName).setValue(readTextStringFromUrl(args.get(i + 1), paramMap.get(paramName).getName())); i++; continue; + } else if (paramMap.get(paramName).getParameterType() .equals(OnapCommandParameterType.ARRAY)) { Object value = paramMap.get(paramName).getValue(); @@ -130,16 +132,20 @@ public class OnapCliArgsParser { paramMap.get(paramName).setValue(list); i++; continue; - } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.MAP)) { + + } else if (paramMap.get(paramName).getParameterType() + .equals(OnapCommandParameterType.MAP)) { Object value = paramMap.get(paramName).getValue(); Map map = (Map) value; String arg = args.get(i + 1); - String[] argArr = arg.split("="); + String[] argArr = arg.split("=", 2); if (argArr.length != 2) { - throw new OnapCliInvalidArgument(paramMap.get(paramName).getName()); + throw new OnapCliInvalidArgument( + paramMap.get(paramName).getName(), + "it should be in the form of ="); } map.put(argArr[0], argArr[1]); @@ -157,7 +163,9 @@ public class OnapCliArgsParser { // it is positional option // Positional arg is missing from the params if (positionalIdx >= positionArgs.size()) { - throw new OnapCliInvalidArgument(args.get(i)); + throw new OnapCliInvalidArgument( + args.get(i), + "No positional argument is defined for this one"); } paramMap.get(positionArgs.get(positionalIdx)).setValue(args.get(i)); -- cgit 1.2.3-korg