如何引用 YAML“设置"?来自同一 YAML 文件中的其他地方? [英] how to reference a YAML "setting" from elsewhere in the same YAML file?

查看:25
本文介绍了如何引用 YAML“设置"?来自同一 YAML 文件中的其他地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 YAML:

paths:
  patha: /path/to/root/a
  pathb: /path/to/root/b
  pathc: /path/to/root/c

如何通过从三个路径中删除 /path/to/root/ 并将其作为自己的设置来规范化"这一点,例如:

How can I "normalise" this, by removing /path/to/root/ from the three paths, and have it as its own setting, something like:

paths:
  root: /path/to/root/
  patha: *root* + a
  pathb: *root* + b
  pathc: *root* + c

显然这是无效的,我只是编造的.真正的语法是什么?能做到吗?

Obviously that's invalid, I just made it up. What's the real syntax? Can it be done?

推荐答案

我不认为这是可能的.您可以重用节点",但不能重用它的一部分.

I don't think it is possible. You can reuse "node" but not part of it.

bill-to: &id001
    given  : Chris
    family : Dumars
ship-to: *id001

这是完全有效的 YAML,givenfamily 字段在 ship-to 块中重复使用.您可以以相同的方式重用标量节点,但您无法更改内部的内容并从 YAML 内部添加路径的最后一部分.

This is perfectly valid YAML and fields given and family are reused in ship-to block. You can reuse a scalar node the same way but there's no way you can change what's inside and add that last part of a path to it from inside YAML.

如果重复让您感到困扰,我建议让您的应用程序了解 root 属性并将其添加到每个看起来相对而不是绝对的路径.

If repetition bother you that much I suggest to make your application aware of root property and add it to every path that looks relative not absolute.

这篇关于如何引用 YAML“设置"?来自同一 YAML 文件中的其他地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆