yaml-cpp
yaml-cpp copied to clipboard
Merge 2 YAML::Node
I use YAML for configuring a software. It looks like this
foo: bar
barafoo:
footabar: foofoofoo
tabafoorab: batabataba
fabfab: 23
I hard-code default values for all of these settings in a default YAML::Node and retrieve user-specified settings from an optional file in /etc/foo/config.yml.
Say /etc/foo/config.yml contains the following
barafoo:
tabafoorab: heyhey
fabfab: 42
I would like to use all the settings from the default YAML::Node (hardcoded in the software) but override those settings if they have different values in /etc/foo/config.yml.
In a sense, I would like to merge 2 YAML::Node, taking all keys from the first one and giving priority to keys in the second one.
Is there something already implemented in yaml-cpp or do I need to write my own function to do that?
I found an answer here https://stackoverflow.com/questions/41326112/how-to-merge-node-in-yaml-cpp but I wonder if there's a better way.
I have exactly the same use case, default configuration plus (partial) override by secondary configuration files. And I would expect this to be a very, very common and recurring use case for many people..
@mfrigerio17 that was my use-case and i ended up using the stackoverflow solution above
This is kind of an auxiliary issue, I think, but I'd accept a PR into the /contrib folder if someone wants to write one or clean up the SO post.