Skip to content

Commit 796eccf

Browse files
committed
feat-#1388 support multiple params with comma after -p
1 parent 67604a0 commit 796eccf

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

chunjun-core/src/main/java/com/dtstack/chunjun/constants/ConstantValue.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class ConstantValue {
2828
public static final String SINGLE_QUOTE_MARK_SYMBOL = "'";
2929
public static final String DOUBLE_QUOTE_MARK_SYMBOL = "\"";
3030
public static final String COMMA_SYMBOL = ",";
31+
public static final String PARAMS_SEP = "-M";
32+
public static final String EMPTY_STR = "";
3133
public static final String SEMICOLON_SYMBOL = ";";
3234

3335
public static final String SINGLE_SLASH_SYMBOL = "/";

chunjun-core/src/main/java/com/dtstack/chunjun/util/JobUtil.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,29 @@ public static String JsonValueReplace(String json, Map<String, String> parameter
4848
return json;
4949
}
5050

51-
/** 将命令行中的修改命令转化为HashMap保存 */
51+
/**
52+
* @param command
53+
* @return HashMap
54+
* @description: convert params after '-p' in shell to hashmap
55+
*/
5256
public static HashMap<String, String> CommandTransform(String command) {
5357
HashMap<String, String> parameter = new HashMap<>();
5458
String[] split = StringUtils.split(command, ConstantValue.COMMA_SYMBOL);
55-
for (String item : split) {
56-
String[] temp = item.split(ConstantValue.EQUAL_SYMBOL);
57-
parameter.put(temp[0].trim(), temp[1].trim());
59+
for (int i = 0; i < split.length; i++) {
60+
String[] params = split[i].split(ConstantValue.EQUAL_SYMBOL);
61+
if (params[0].trim().startsWith(ConstantValue.PARAMS_SEP)) {
62+
StringBuilder sb = new StringBuilder();
63+
sb.append(params[1]);
64+
while (i + 1 < split.length && !split[i + 1].contains(ConstantValue.EQUAL_SYMBOL)) {
65+
sb.append(ConstantValue.COMMA_SYMBOL + split[i + 1]);
66+
i++;
67+
}
68+
String key =
69+
params[0].trim().replace(ConstantValue.PARAMS_SEP, ConstantValue.EMPTY_STR);
70+
parameter.put(key, sb.toString());
71+
} else {
72+
parameter.put(params[0].trim(), params[1].trim());
73+
}
5874
}
5975
return parameter;
6076
}

0 commit comments

Comments
 (0)