Roger-luo / Configurations.jl

Options & Configurations made easy.
https://configurations.rogerluo.dev/stable
MIT License
80 stars 12 forks source link

Can I `merge` two configurations? #20

Closed fonsp closed 3 years ago

fonsp commented 3 years ago

It would be great if something like this could work:

options_from_toml = Configurations.from_toml(Settings, "options.toml")
options_from_kwargs = Configurations.from_kwargs(Settings, kwargs)

final_options = merge(options_from_toml, options_from_kwargs) # kwargs take precedence

Or is there a suggested method to achieve the same result?

Roger-luo commented 3 years ago

this sounds reasonable, but it's not implemented yet, I guess I forget to implement it somehow

Roger-luo commented 3 years ago

I'm doing a clean up of this package to split things, I'll implement this in the next version.

Roger-luo commented 3 years ago

I find you actually want

from_toml(Settings, "options.toml"; kwargs...)

after implementing merge, I find it's different from a mutable Dict here, since two options types contains each default values, so in some cases it won't make sense to overwrite the first option with the second (since what you actually want to do is to only overwrite what is specified by the keywords)