config
config copied to clipboard
Include directives
Hello,
first of all, thank for the great package. I found it very usefull.
With this PR I would like to introduce the ability to instruct the loader to load additional configuration files and merge them with the main file right from configuration files. Sounds tricky. :)
So the idea is simple and looks like C preprocessor. There are two directives for loading files, e.g.
; Try to load some file
#include some/file.cfg
; Require file to be loaded and merged
#require /etc/supertool/db.cfg
[this]
is: section
Of course, you can use Merge
function for merging multiple files into one but that new feature makes it much easier to maintain multi-file configurations.
So that PR should not break any existing code because it does not change the existing syntax and utilizes comments for directives.
Also added the ability to use globs (wildcards) in include paths, e.g. #include user/*.cfg
.
Hi, thank you for the contribution!
Regarding the new directives, having two directives that do almost the same thing doesn't seem great, and I can easily imagine that users are surprised by the #include behavior if they have used similar directives other places. I haven't seen this sort of paradigm in other places, so maybe having a single directive (#include, that requires the file to exist) is sufficient?
For a use case where you want to suppose a stock config and the user can provide additional values in a separate file (my assumption for your use case of #include), I would suggest these two workarounds:
- Create the file by default, and have it be empty with a comment saying the user can add keys to it
- Comment out the #include directive, with a comment saying user can uncomment and point it to their file.
Does that sound ok for your use case?
Thanks again!
Ok. I think you are right and that sounds good to me. Let it be only one directive #include
then, which acts in the strict manner like #require
.
@robfig I fixed it. There is only one directive #include
here.