mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
fix missing case of multiple argv values in single provided at-line for global option
This commit is contained in:
parent
9cd542ab30
commit
f4f70b9ea7
@ -100,7 +100,7 @@ public class NBAtFile {
|
||||
}
|
||||
Content<?> argsContent = wantsExtension.one();
|
||||
String argsdata = argsContent.asString();
|
||||
Fmt fmt = (formatSpec!=null) ? Fmt.valueOfSymbol(formatSpec) : Fmt.Default;
|
||||
NBAtFileFormats fmt = (formatSpec!=null) ? NBAtFileFormats.valueOfSymbol(formatSpec) : NBAtFileFormats.Default;
|
||||
|
||||
Object scopeOfInclude = null;
|
||||
try {
|
||||
@ -124,7 +124,7 @@ public class NBAtFile {
|
||||
|
||||
}
|
||||
|
||||
private static LinkedList<String> formatted(Object scopeOfInclude, Fmt fmt) {
|
||||
private static LinkedList<String> formatted(Object scopeOfInclude, NBAtFileFormats fmt) {
|
||||
LinkedList<String> emitted = new LinkedList<>();
|
||||
if (scopeOfInclude instanceof Map<?,?> map) {
|
||||
Map<String,String> included = new LinkedHashMap<>();
|
||||
|
@ -19,25 +19,27 @@ package io.nosqlbench.engine.cli.atfiles;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public enum Fmt {
|
||||
public enum NBAtFileFormats {
|
||||
Default("", s -> s.length <=2, s -> (s.length==1) ? s[0] : s[0] + ":" + s[1]),
|
||||
MapWithEquals("=", s -> s.length == 2, s -> s[0] + "=" + s[1]),
|
||||
MapWithColons(":", s -> s.length == 2, s -> s[0] + ":" + s[1]),
|
||||
GlobalWithDoubleDashes("--", s -> s.length ==1 && s[0].startsWith("--"), s -> s[0]);
|
||||
GlobalWithDoubleDashes("--", s -> s.length<=2 && s[0].startsWith("--"), NBAtFileFormats::formatDashDashOption);
|
||||
|
||||
private final String spec;
|
||||
private final Predicate<String[]> validator;
|
||||
private final Function<String[], String> formatter;
|
||||
|
||||
Fmt(String spec, Predicate<String[]> validator, Function<String[], String> formatter) {
|
||||
NBAtFileFormats(String spec, Predicate<String[]> validator, Function<String[], String> formatter) {
|
||||
this.spec = spec;
|
||||
this.validator = validator;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
public static Fmt valueOfSymbol(String s) {
|
||||
for (Fmt value : values()) {
|
||||
public static NBAtFileFormats valueOfSymbol(String s) {
|
||||
for (NBAtFileFormats value : values()) {
|
||||
if (value.spec.equals(s)) {
|
||||
return value;
|
||||
}
|
||||
@ -50,6 +52,33 @@ public enum Fmt {
|
||||
throw new RuntimeException("With fmt '" + this.name() + "': input data not valid for format specifier '" + spec + "': data:[" + String.join("],[",Arrays.asList(ary)) + "]");
|
||||
}
|
||||
}
|
||||
|
||||
private final static Pattern doubleOptionSpace = Pattern.compile(
|
||||
"^(?<optname>--[a-zA-Z][a-zA-Z0-9_.-]*) +(?<optvalue>.+)$"
|
||||
);
|
||||
|
||||
private static String formatDashDashOption(String[] words) {
|
||||
|
||||
if (words[0].contains("=")) {
|
||||
if (words.length==1) {
|
||||
return words[0];
|
||||
} else {
|
||||
throw new RuntimeException("Unrecognized option form " + String.join(" (space) " + Arrays.asList(words)));
|
||||
}
|
||||
}
|
||||
if (words.length>1) {
|
||||
throw new RuntimeException("too many values for rendering --option in at-file: " + Arrays.asList(words));
|
||||
}
|
||||
Matcher matcher = doubleOptionSpace.matcher(words[0]);
|
||||
if (matcher.matches()) {
|
||||
String optname = matcher.group("optname");
|
||||
String optvalue = matcher.group("optvalue");
|
||||
return optname + "=" + optvalue;
|
||||
} else {
|
||||
throw new RuntimeException("Unable to convert atfile option: "+ Arrays.asList(words));
|
||||
}
|
||||
}
|
||||
|
||||
public String format(String[] ary) {
|
||||
return formatter.apply(ary);
|
||||
}
|
Loading…
Reference in New Issue
Block a user