Skip to content

Commit

Permalink
fix: support single line
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Mar 24, 2023
1 parent a8471c3 commit 51272fa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ public static String expand(String value, Path directory) throws IOException {

@SneakyThrows
private static String expandLine(String line, Path directory) {
String indent = line.substring(0, line.indexOf("[[>"));
String prefix = line.substring(0, line.indexOf("[[>"));
String suffix = line.substring(line.indexOf("]]") + 2, line.length());
String file = line.substring(line.indexOf("[[>") + 3 , line.indexOf("]]")).strip();
Path includePath = directory.resolve(file);
List<String> include = Files.readLines(includePath.toFile(), Charset.defaultCharset());

// handle single line directly with the suffix (should be between quotes or double-quotes
if(include.size() == 1) {
String singleInclude = include.get(0);
return prefix + singleInclude + suffix;
}

// multi-line will be expanded with the prefix but no suffix
return include.stream()
.map(includeLine -> indent + includeLine)
.map(includeLine -> prefix + includeLine)
.collect(Collectors.joining("\n"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ void run() {
"tasks:\n" +
"- id: t1\n" +
" type: io.kestra.core.tasks.debugs.Return\n" +
" format: \"Lorem ipsum dolor sit amet\"\n" +
"- id: t2\n" +
" type: io.kestra.core.tasks.debugs.Return\n" +
" format: |\n" +
" Lorem ipsum dolor sit amet\n" +
" Lorem ipsum dolor sit amet\n"
Expand Down
5 changes: 4 additions & 1 deletion cli/src/test/resources/helper/flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace: io.kestra.cli
# The list of tasks
tasks:
- id: t1
type: io.kestra.core.tasks.debugs.Return
format: "[[> lorem.txt]]"
- id: t2
type: io.kestra.core.tasks.debugs.Return
format: |
[[> lorem.txt]]
[[> lorem-multiple.txt]]
2 changes: 2 additions & 0 deletions cli/src/test/resources/helper/lorem-multiple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Lorem ipsum dolor sit amet
Lorem ipsum dolor sit amet
1 change: 0 additions & 1 deletion cli/src/test/resources/helper/lorem.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Lorem ipsum dolor sit amet
Lorem ipsum dolor sit amet

0 comments on commit 51272fa

Please sign in to comment.