task icon indicating copy to clipboard operation
task copied to clipboard

strange syntax error, only difference is a space.

Open bayeslearnerold opened this issue 1 year ago • 1 comments

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?

bayeslearnerold avatar Feb 03 '24 04:02 bayeslearnerold

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 avatar Mar 31 '24 20:03 trulede

@trulede is right!

vmaerten avatar May 19 '24 15:05 vmaerten