rust-cli/confy

Custom Name for Config Files

Closed this issue · 4 comments

strix commented

First of all, I love the convenience that this package provides but I ran into a problem that might have a simple solution.
I want to have multiple config files per project. For example, I would like to store/load the following files on Linux:

~/.config/app-name/config1.toml
~/.config/app-name/config2.toml
~/.config/app-name/config3.toml

With confy's current functionality I can only generate a ~/.config/app-name/app-name.toml file but I'd like to have multiple configs per project.

I've got a quick solution working for me on a fork but it would be nice if this kind of functionality could be in the official package.

Why can't you use the load() function with load("config1"), load("config2") and so on?

strix commented

Why can't you use the load() function with load("config1"), load("config2") and so on?

Doing that (on Linux) would result in:

~/.config/config1/config1.toml
~/.config/config2/config2.toml

This happens because the name parameter is being used for both retrieving the config path (using ProjectDirs::from) and to set the file name.

Ah. Sure. Did not read the code close enough. Well, I'm not sure about the others, but I'd love to see a patch for that usecase.

I have the exact same use case. It would be nice to have a comment by the maintainers if this behaviour is wanted or not; since it could/would add more complexity to the usage of the API and the goal of this crate is to make configs as easy as possible.