config icon indicating copy to clipboard operation
config copied to clipboard

Include directives

Open workanator opened this issue 7 years ago • 4 comments

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 avatar Mar 17 '17 10:03 workanator

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

workanator avatar Mar 17 '17 12:03 workanator

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!

robfig avatar Mar 20 '17 01:03 robfig

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 avatar Mar 20 '17 03:03 workanator

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

workanator avatar Mar 20 '17 04:03 workanator