mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
Added suport for multiline variables from sh
Instead of giving an error on multiline results from sh, the results are now stored as is, except that the last newline is stripped away to make the output of most commands easy to use in shell commands. Two helper functions have been added to help deal with multi-line results. In addition, previous PascalCase template function names have been renamed to camelCase for consistency with the sprig lib.
This commit is contained in:
committed by
Sindre Røkenes Myren
parent
36f3be9979
commit
7a64530e83
43
testdata/vars/multiline/Taskfile.yml
vendored
Normal file
43
testdata/vars/multiline/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
default:
|
||||
vars:
|
||||
MULTILINE: "\n\nfoo\n bar\nfoobar\n\nbaz\n\n"
|
||||
cmds:
|
||||
- task: file
|
||||
vars:
|
||||
CONTENT:
|
||||
sh: "echo 'foo\nbar'"
|
||||
FILE: "echo_foobar.txt"
|
||||
- task: file
|
||||
vars:
|
||||
CONTENT:
|
||||
sh: "echo -n 'foo\nbar'"
|
||||
FILE: "echo_n_foobar.txt"
|
||||
- task: file
|
||||
vars:
|
||||
CONTENT:
|
||||
sh: echo -n "{{.MULTILINE}}"
|
||||
FILE: "echo_n_multiline.txt"
|
||||
- task: file
|
||||
vars:
|
||||
CONTENT: "{{.MULTILINE}}"
|
||||
FILE: "var_multiline.txt"
|
||||
- task: file
|
||||
vars:
|
||||
CONTENT: "{{.MULTILINE | catLines}}"
|
||||
FILE: "var_catlines.txt"
|
||||
- task: enumfile
|
||||
vars:
|
||||
LINES: "{{.MULTILINE}}"
|
||||
FILE: "var_enumfile.txt"
|
||||
file:
|
||||
cmds:
|
||||
- |
|
||||
cat << EOF > '{{.FILE}}'
|
||||
{{.CONTENT}}
|
||||
EOF
|
||||
enumfile:
|
||||
cmds:
|
||||
- |
|
||||
cat << EOF > '{{.FILE}}'
|
||||
{{range $i, $line := .LINES| splitLines}}{{$i}}:{{$line}}
|
||||
{{end}}EOF
|
Reference in New Issue
Block a user