task icon indicating copy to clipboard operation
task copied to clipboard

Cannot programmatically generate dependencies for a task

Open postlund opened this issue 3 years ago • 2 comments

  • Task version: v3.12.0 (h1:viFy8kdDZ2iTcpTuxzzJCeKtTGt9U+5iXMVIpLjvIro=)
  • Operating System: Linux 5.10.16.3-microsoft-standard-WSL2

Example Taskfile showing the issue

I want to programmatically generate deps in a task based on the content of a variable, but it seems to be some problems when converting the string to a list. Here is a basic example:

version: '3'

env:
  DEPS: "foo bar"

tasks:
  default:
    deps: {{ splitList " " .DEPS }}
    cmds:
      - echo default

  foo:
    cmds:
      - echo foo

  bar:
    cmds:
      - echo bar

Which generates this error:

$ ./build
yaml: unmarshal errors:
  line 8: cannot unmarshal !!map into []*taskfile.Dep

I assume something like this should work?

postlund avatar Apr 22 '22 05:04 postlund

You will have to quote {{ splitList " " .DEPS }} as currently it is picked up as a map by the YAML parser, and consequently Go text templating won't be ran for it.

Furthermore, the thing you have to remember, these are Go text templates, the result is text (i.e. a string), I'm not that familiar with Taskfile but I'm not aware of any functionality it that will unmarshal a YAML string to a YAML like structure which is what you will need in this case.

aucampia avatar Apr 24 '22 19:04 aucampia

I'm working on a v4 that will be able to handle this functionality

ghostsquad avatar Apr 25 '22 01:04 ghostsquad