Splat doesn't work for array - yq

Describe the bug The splat operator doesn't work with arrays.

Version of yq: 4.12.0 Operating system: windows Installed via: binary release

Input Yaml example.yml:

spec:
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-frontend
        image: myrepo.azurecr.io/myapp-frontend:latest
      - name: myapp-backend
        image: myrepo.azurecr.io/myapp-backend:latest

Command

works correctly using integer:

yq eval '.spec.template.spec.containers[0].image' ./example.yaml
myrepo.azurecr.io/myapp-frontend:latest
yq eval '.spec.template.spec.containers[1].image' ./example.yaml
myrepo.azurecr.io/myapp-backend:latest

fails with error using splat:

yq eval '.spec.template.spec.containers[*].image' ./example.yaml
Error: '' expects 2 args but there is 1
Asked Sep 28 '21 09:09
avatar ggolub
ggolub

2 Answer:

While the docs do show usage with '*', omitting that seems to work as expected. Closing.

1
Answered Aug 25 '21 at 19:27
avatar  of ggolub
ggolub

I took a quick look and can't find it again. I'd cleared my browser history so that isn't of any use. I strongly suspect I was looking at v2, not the current version. If I run across it again I'll add a comment with details. Sorry for the false alarm.

1
Answered Aug 26 '21 at 11:17
avatar  of ggolub
ggolub