请帮助合并dict与锚在YAML文件,我尝试这样做,但YAML返回错误的结果。谢谢你的帮助
common_files: &common_files
- file_path: "link -1"
content_pattern:
- "text"
- "text"
one: "zoo"
two: "foo"
three: "fii"
- file_path: "link -2"
content_pattern:
- "text"
- "text"
one: "zoo"
two: "foo"
three: "fii"
files:
- <<: *common_files
- file_path: "link-3"
content_pattern:
- "text"
- "text"
one: "zoo"
two: "foo"
three: "fii" 发布于 2022-02-25 11:27:44
<<在映射上工作,但是您试图使它在序列上工作。这是不可能的您可以通过别名单独包含公共文件,例如:
common_files:
- &link1
file_path: "link -1"
content_pattern:
- "text"
- "text"
one: "zoo"
two: "foo"
three: "fii"
- &link2
file_path: "link -2"
content_pattern:
- "text"
- "text"
one: "zoo"
two: "foo"
three: "fii"
files:
- *link1
- *link2
- file_path: "link-3"
content_pattern:
- "text"
- "text"
one: "zoo"
two: "foo"
three: "fii" 合并是一个非标准的YAML功能。序列没有类似的特性。我所知道的任何实现都没有提供您需要用一个命令将所有common_files添加到文件中所需的内容。
https://stackoverflow.com/questions/71264812
复制相似问题