aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2018-12-10 14:43:52 +0100
committerbogumil_zebek <bogumil.zebek@nokia.com>2018-12-10 14:43:52 +0100
commit918dfc86667cd6379285722715827ea03b7f6a86 (patch)
tree2651bad22cb6218110dd7d0ff8094ffe9d282640 /src/main/java
parent1afc93ddb4afc226562043822f6c5e9dc0ed4b2a (diff)
Simplify cli parser logic
Change-Id: I7008efe19f567b178dd296f4f485fd14c5e7569d Issue-ID: DCAEGEN2-1022 Signed-off-by: bogumil_zebek <bogumil.zebek@nokia.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/dcae/CLIUtils.java37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/main/java/org/onap/dcae/CLIUtils.java b/src/main/java/org/onap/dcae/CLIUtils.java
index 6764d5b2..40cbb6be 100644
--- a/src/main/java/org/onap/dcae/CLIUtils.java
+++ b/src/main/java/org/onap/dcae/CLIUtils.java
@@ -21,33 +21,34 @@
package org.onap.dcae;
+import io.vavr.collection.Map;
+
import java.util.HashMap;
-/**
- * CLIUtils extracted from nsaServerLibrary this implementation will be removed once we switch to different API library
- */
public class CLIUtils {
- public static io.vavr.collection.HashMap<String, String> processCmdLine(String[] args) {
- final HashMap<String, String> map = new HashMap<String, String>();
+ public static Map<String, String> processCmdLine(String[] args) {
+ final java.util.Map<String, String> map = new HashMap<>();
+
+ String argumentName = null;
- String lastKey = null;
for (String arg : args) {
- if (arg.startsWith("-")) {
- if (lastKey != null) {
- map.put(lastKey.substring(1), "");
- }
- lastKey = arg;
+ if (isArgumentName(arg)) {
+ argumentName = resolveArgumentName(arg);
+ map.put(argumentName, "");
} else {
- if (lastKey != null) {
- map.put(lastKey.substring(1), arg);
- }
- lastKey = null;
+ map.put(argumentName, arg);
}
}
- if (lastKey != null) {
- map.put(lastKey.substring(1), "");
- }
+
return io.vavr.collection.HashMap.ofAll(map);
}
+
+ private static String resolveArgumentName(String arg) {
+ return arg.substring(1);
+ }
+
+ private static boolean isArgumentName(String arg) {
+ return arg.startsWith("-");
+ }
}