如何在 YAML 中正确地将 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"
Please help merge dict with anchor in YAML to files, I try to do this but YAML return wrong result. Thanks for help
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
<<
适用于映射,但您尝试使其适用于序列。这是不可能的。您可以通过别名单独包含公共文件,例如:合并是非标准 YAML 功能。序列没有类似的功能。据我所知,没有任何实现可以提供您使用一个命令将所有common_files添加到文件所需的功能。
<<
works on mappings, but you try to make it work on sequences. This is not possible. You can include the common files individually via alias, eg:Merge is a non-standard YAML feature. There is no similar feature for sequences. No implementation I know of provides what you'd need to prepend all common_files to files with one command.