Skip to content

Be able to use variables inside variable names #2070

@MetalArend

Description

@MetalArend

Description

tasks:
  do:*:
    vars:
      THING: "{{index .MATCH 0}}"
      _FIRST_THING: "one"
      _SECOND_THING: "two"
    requires:
      vars:
        - name: THING
          enum: [ first, second ]
    cmds:
      - echo "{{.THING}}" # first
      - echo "._{{.THING | upper}}_THING" # ._FIRST_THING
      - echo "{{"{{"}}._{{.THING | upper}}_THING{{"}}"}}" # {{._FIRST_THING}}
      - echo "{{._{{.THING | upper}}_THING}}" # This does not work, should print "one" for `task do:first`

If I would run task do:first, it would be awesome to be able to use the variable THING to get to the parsing of {{._FIRST_THING}} and echo "one" in the last command.

I can get something similar to work when doing an extra call to force a second render, but it would be nice if this could be done in a more direct way.

tasks:
  _do-through-loop:
    requires:
      vars: [OUTPUT]
    cmds:
      - echo "{{.OUTPUT}}"

  do-through-loop:*:
    vars:
      THING: "{{index .MATCH 0}}"
    requires:
      vars:
        - name: THING
          enum: [ first, second ]
    cmds:
      - task: '_do-through-loop'
        vars:
          OUTPUT: '{{"{{"}}._{{.THING | upper}}_THING{{"}}"}}'
          _FIRST_THING: "one"
          _SECOND_THING: "two"

Here's me hoping that second example is not going to be recognised as a bug, and eventually be removed 🤞

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions