task
task copied to clipboard
strange syntax error, only difference is a space.
switch_context:
desc: "Switch to a different context."
vars:
NEW_CONTEXT_NAME: "{{.NEW_CONTEXT_NAME | default ``}}"
cmds:
- echo 'Switching to context:' '{{.NEW_CONTEXT_NAME}}'
- echo 'Switching to context:{{.NEW_CONTEXT_NAME}}'
- echo 'Switching to context: {{.NEW_CONTEXT_NAME}}'
- sed -i.bak 's/^export CONTEXT_NAME=.*/export CONTEXT_NAME="{{.NEW_CONTEXT_NAME}}"/' "{{.ROOT_DIR}}/.envrc.context"
- rm "{{.ROOT_DIR}}/.envrc.context.bak"
- direnv allow "{{.ROOT_DIR}}"
The third echo will cause syntax errors. Why?
The sequence ": " seems to be interpreted as a YAML Map which contradicts the Taskfile schema (where commands should be a string). The following work:
version: '3'
tasks:
foo:
vars:
BAR: '{{.BAR | default "foo"}}'
cmds:
- echo {{.BAR}}
- echo 'message:{{.BAR}}'
- echo message:\ {{.BAR}}
- echo 'message:\ {{.BAR}}'
- "echo message: {{.BAR}}"
- |
echo message: {{.BAR}}
- >
echo message: {{.BAR}}
I guess that is your problem.
@trulede is right!