You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you can see, dictionaries are merged in a semi-intelligent way, to allow for overriding nested values without overwriting entire sub-dictionaries. This is what I wanted for my use-case, but might not always be desirable.
I wanted to share my solution here in case it's helpful to anyone else wanting to do the same, and also to ask if something like this could feasibly be integrated into yglu itself, e.g.
Many thanks for this contribution.
I was pretty sure that such a feature would be the first to be requested :)
As you say, the merge strategy should be adaptable to the cases. We should be able to specify nodes that must be replaced, merged or deleted.
I did some tries in this direction in the "overlay" branch. (https://github.com/lbovet/yglu/blob/overlay/tests/future/overlay.yml).
I am not yet happy with the result, it is too complex. IMHO.
If you have ideas about the syntax users should use to specify the merge strategy, they are welcome.
Also, in the meantime, until there is a native answer implemented in Yglu, it could be interesting to make your solution easily usable for anyone. You could move _imported and _import in a separated reusable file. Users would just have to import this file and call a function.
If you want to try contributing this, feel free to open a PR with a functioning test in https://github.com/lbovet/yglu/tree/master/tests/samples
lbovet
changed the title
importing directly into document root
Merge imported files into document root
May 9, 2020
I wanted to be able to import one or more yaml documents into the root of another document, but this doesn't seem easily doable with yglu as-is.
I was able to craft a bit of a hacky way to accomplish my goal - here is what I came up with:
The output is:
As you can see, dictionaries are merged in a semi-intelligent way, to allow for overriding nested values without overwriting entire sub-dictionaries. This is what I wanted for my use-case, but might not always be desirable.
I wanted to share my solution here in case it's helpful to anyone else wanting to do the same, and also to ask if something like this could feasibly be integrated into yglu itself, e.g.
I also wrote a script to inject the yglu code to do the importing whenever a
_import: !()
line is detected and pass it through yglu: link.p.s. Thank you for yglu, it is really useful!
The text was updated successfully, but these errors were encountered: