Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would you consider modification of config files? #29

Closed
ModProg opened this issue Apr 17, 2023 · 7 comments
Closed

Would you consider modification of config files? #29

ModProg opened this issue Apr 17, 2023 · 7 comments

Comments

@ModProg
Copy link

ModProg commented Apr 17, 2023

It's a project I'm currently planing but haven't really found how I want to do yet, and I stumbled upon this crate looking for a name.

@LukasKalbertodt
Copy link
Owner

Hi. I'm sorry but I think you need to provide a bit more context. What do you mean by "modification of config files"?

@ModProg
Copy link
Author

ModProg commented Apr 17, 2023

In the end, I want to provide a git config like sub command, that can set and query configuration values. But the need to modify the on disc configuration file can also arise from, e.g. GUI applications that have a settings menu on top of a human-readable on disc configuration file (e.g. VS Code).

@LukasKalbertodt
Copy link
Owner

Ah I see. That makes sense. This is something I very likely will consider for confique. In fact I might have this exact requirement very soon in one of my own projects in which I plan to use confique. So I will likely see about it then.

However, already now I am not sure how well confique can support it. Just serializing the whole configuration and writing it to the file again is fairly easy, but overwrites the whole file. That means that comments made by the user for example are overwritten. I am not sure confique will ever support this "only change what's necessary but keep the original file as much as possible". It's not easy. Would that be a requirement for you?

But yes, the basic "write an in-memory config to file" will certainly be supported. Likely also with the option to write or not write default values and the like.

@ModProg
Copy link
Author

ModProg commented Apr 17, 2023

I would want to keep comments and such, but that would require to not use serde for the writing but a different trait that could ask a Config provider to only write the changes but keep the rest of the file as is without breaking any formatting or comments. For toml this could be achieved with toml-edit and there are probably similar crates for other file formats, but this increases the custom code to maintain as one cannot rely on the serde infrastructure as much if at all.

@LukasKalbertodt
Copy link
Owner

Yep :/ I am very sure that confique will stay with serde and not pull in any other dependencies.

@ModProg
Copy link
Author

ModProg commented Apr 17, 2023

I experimented a bit, and it looks like it wouldn't be too terrible to do a serde serializer that preservers the original data if possible: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dbda15adfbdf58defcaf2c5707a3a033

It uses toml-edit which would already be a dependency through toml.

Granted this is only a very incomplete implementation for toml one would need to repeat that for all supported data formats. But maybe there would be a way to design this in a way where these "modifying serializers" could be brought in externally from a confique consumer.

@LukasKalbertodt
Copy link
Owner

I combined multiple issues into one: #41

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

No branches or pull requests

2 participants