【发布时间】:2022-08-04 14:13:18
【问题描述】:
考虑以下hello.yaml:
foos:
- foo: foo1
bar: hello
- foo: foo2
bar: world
如果我想更新bar 的值foo = \"foo1\",我可以调用以下命令:
yq \'( .foos[] | select(.foo == \"foo1\") | .bar) |= \"goodbye cruel\"\' hello.yaml
并且正确输出:
foos:
- foo: foo1
bar: goodbye cruel
- foo: foo2
bar: world
但是,如果我不知道我有匹配的项目,我想插入适当的条目,例如像yq \'( .foos[] | select(.foo == \"foo3\") | .bar) ... 这样的东西会输出
foos:
- foo: foo1
bar: hello
- foo: foo2
bar: world
- foo: foo3
bar: goodbye cruel
yq 中有没有办法“更新”数组,或者我是否必须预先评估密钥是否存在并执行两个命令之一来插入或更新?
非常感谢
-
当前版本没有
upsert方式。最好的选择是检查并插入