Skip to content

Conversation

@workanator
Copy link

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.

@workanator
Copy link
Author

Also added the ability to use globs (wildcards) in include paths, e.g. #include user/*.cfg.

@robfig
Copy link
Owner

robfig commented Mar 20, 2017

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:

  1. Create the file by default, and have it be empty with a comment saying the user can add keys to it
  2. 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!

@workanator
Copy link
Author

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.

@workanator
Copy link
Author

@robfig I fixed it. There is only one directive #include here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants