Skip to content

Evalsubst operator #2551

@kknicker

Description

@kknicker

Add an "evalsubst" operator similar to "envsubst", to evaluate values as yq expressions.

It would be nice to have the ability to handle plain expressions or strings with interpolated expressions, and results which can be a string or an object. Examples are below.

yq '(.. | select(tag == "!!str")) |= evalsubst' t.yaml

Example 1:

vars:
  x: 1
  y: 2
z: \(.vars | .x + .y)
vars:
  x: 1
  y: 2
z: 3

Example 2:

vars:
  x: 1
  y: 2
z: The answer is \(.vars | .x + .y)
vars:
  x: 1
  y: 2
z: The answer is 3

Example 3:

vars:
  x: 1
  y: 2
z: \(.vars)
vars:
  x: 1
  y: 2
z:
  x: 1
  y: 2

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions