Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to resolve refs using templating syntax #1612

Merged
merged 4 commits into from
Apr 24, 2024
Merged

Conversation

pd93
Copy link
Member

@pd93 pd93 commented Apr 22, 2024

This PR adds the ability to resolve references to other variables using Golang's templating syntax.

For example:

version: '3'

tasks:
  ref-resolver:
    vars:
      MAP:
        map: {"name":"Alice","age":30,"children":[{"name":"Bob","age":5},{"name":"Charlie","age":3},{"name":"Diane","age":1}]}
      MAP_REF:
        ref: .MAP # <-- now requires "dot" syntax
    cmds:
      - task: print-var
        vars:
          VAR:
            ref: (index .MAP_REF.children 0).name # <-- use brackets and functions normally

  print-var:
    cmds:
      - echo "{{.VAR}}" # <-- echos "Bob"

Since this functionality is not exposed by the standard library, it depends on a fork of the text/template package and the changes in this PR.

@pd93 pd93 enabled auto-merge (squash) April 24, 2024 18:55
@pd93 pd93 merged commit 630e587 into main Apr 24, 2024
13 checks passed
@pd93 pd93 deleted the resolve-refs branch April 24, 2024 19:47
pd93 added a commit that referenced this pull request Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants