config-rs icon indicating copy to clipboard operation
config-rs copied to clipboard

Introduce an option for disabling the automatic resolver in FileSourceFile

Open eisterman opened this issue 5 years ago • 6 comments

A new feature with granted retro compatibility. To solve the problem introduced in https://github.com/mehcode/config-rs/issues/132 I have introduced the solution number 3:

Add a flag to the FileSourceFile struct named use_resolver and add a method in File<FileSourceFile> similar to required(bool) where the user can enable or disable the resolver in FileSourceFile (The best solution. No breaking change, no removing of feature, only adding an option flag that if not used will be set to True for retro compatibility)

The struct File now has two new methods, with_exact_name and exact_name, the first to create a File with a FileSourceFile imposed to not search the extension of the file. With this approach, one can load a file named Settings.wrongextension as a Toml file like before, but if the file is missing the program will not search another file named for example Settings.yaml without asking.

I've introduced three tests for the new methods, and a very small fix of the wrong extension error message, because before it used the absolute path when the not found error used the relative/given path.

eisterman avatar Mar 14 '20 03:03 eisterman

I see where this is coming from. First, thanks for the contribution. I agree as well that your solution #3 is probably the best way to handle this.

Very minor nit, should we have the option method simply exact instead of exact_name? I think it conveys the same information in context:

File::with_name("Config.toml").exact(true)
File::with_exact_name("Config.toml")

mehcode avatar Mar 15 '20 00:03 mehcode

I agree it is certainly more coherent and sensible as a name. I sent the name change commit.

eisterman avatar Mar 15 '20 00:03 eisterman

Do you need anything else for the merge?

eisterman avatar Mar 28 '20 18:03 eisterman

Any problems?

eisterman avatar May 28 '20 21:05 eisterman

Are you still interested in this?

If yes, I created a maintenance fork (read here). Feel free to submit your patches! :smile:

matthiasbeyer avatar Mar 13 '21 10:03 matthiasbeyer

Can you rebase this to latest master?

matthiasbeyer avatar Mar 17 '21 16:03 matthiasbeyer