mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
allow atfiles to relativize for ${DIR} patterns
This commit is contained in:
parent
77680f480f
commit
e2d8f332fb
@ -104,6 +104,7 @@ public class NBAtFile {
|
|||||||
|
|
||||||
filepathSpec=(filepathSpec.endsWith(".yaml") ? filepathSpec : filepathSpec+".yaml");
|
filepathSpec=(filepathSpec.endsWith(".yaml") ? filepathSpec : filepathSpec+".yaml");
|
||||||
Path atPath = Path.of(filepathSpec);
|
Path atPath = Path.of(filepathSpec);
|
||||||
|
|
||||||
String argsdata = "";
|
String argsdata = "";
|
||||||
try {
|
try {
|
||||||
argsdata = Files.readString(atPath);
|
argsdata = Files.readString(atPath);
|
||||||
@ -128,13 +129,28 @@ public class NBAtFile {
|
|||||||
throw new RuntimeException("You can not traverse a non-map object type with spec '" + spec + "'");
|
throw new RuntimeException("You can not traverse a non-map object type with spec '" + spec + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return formatted(scopeOfInclude, fmt);
|
LinkedList<String> formatted = formatted(scopeOfInclude, fmt);
|
||||||
|
formatted=interposePath(formatted, atPath);
|
||||||
|
return formatted;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unable to match at-file specifier: " + spec + " to pattern '" + includePattern.pattern() + "'");
|
throw new RuntimeException("Unable to match at-file specifier: " + spec + " to pattern '" + includePattern.pattern() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static LinkedList<String> interposePath(LinkedList<String> formatted, Path atPath) {
|
||||||
|
Path parent = (atPath.getNameCount()==1 ? Path.of(".") : atPath.getParent());
|
||||||
|
|
||||||
|
ListIterator<String> iter = formatted.listIterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String word = iter.next();
|
||||||
|
String modified = word.replaceAll("\\$\\{DIR}",parent.toString());
|
||||||
|
iter.remove();
|
||||||
|
iter.add(modified);
|
||||||
|
}
|
||||||
|
return formatted;
|
||||||
|
}
|
||||||
|
|
||||||
private static LinkedList<String> formatted(Object scopeOfInclude, NBAtFileFormats fmt) {
|
private static LinkedList<String> formatted(Object scopeOfInclude, NBAtFileFormats fmt) {
|
||||||
LinkedList<String> emitted = new LinkedList<>();
|
LinkedList<String> emitted = new LinkedList<>();
|
||||||
if (scopeOfInclude instanceof Map<?,?> map) {
|
if (scopeOfInclude instanceof Map<?,?> map) {
|
||||||
|
@ -31,6 +31,12 @@ class NBAtFileTest {
|
|||||||
assertThat(strings).containsExactly("arg1","arg2","arg3");
|
assertThat(strings).containsExactly("arg1","arg2","arg3");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRelativizedPaths() {
|
||||||
|
LinkedList<String> strings = NBAtFile.includeAt("@src/test/resources/atfiles/relativized.yaml");
|
||||||
|
assertThat(strings).containsExactly("--option1=src/test/resources/atfiles/value1");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseSimpleMapDefaultFmt() {
|
public void testParseSimpleMapDefaultFmt() {
|
||||||
LinkedList<String> strings = NBAtFile.includeAt("@src/test/resources/atfiles/simple_map.yaml");
|
LinkedList<String> strings = NBAtFile.includeAt("@src/test/resources/atfiles/simple_map.yaml");
|
||||||
|
1
engine-cli/src/test/resources/atfiles/relativized.yaml
Normal file
1
engine-cli/src/test/resources/atfiles/relativized.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
- --option1=${DIR}/value1
|
Loading…
Reference in New Issue
Block a user