首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >YAML中如何正确合并dict与锚

YAML中如何正确合并dict与锚
EN

Stack Overflow用户
提问于 2022-02-25 10:58:07
回答 1查看 494关注 0票数 1

请帮助合并dict与锚在YAML文件,我尝试这样做,但YAML返回错误的结果。谢谢你的帮助

代码语言:javascript
复制
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" 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-25 11:27:44

<<在映射上工作,但是您试图使它在序列上工作。这是不可能的您可以通过别名单独包含公共文件,例如:

代码语言:javascript
复制
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添加到文件中所需的内容。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71264812

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档