问题描述
我有以下 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,given
和 family
字段在 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 文件中的其他地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!