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

查看:610
本文介绍了如何引用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天全站免登陆