Code Monkey home page Code Monkey logo

Comments (6)

LukasKalbertodt avatar LukasKalbertodt commented on May 20, 2024

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

from confique.

ModProg avatar ModProg commented on May 20, 2024

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).

from confique.

LukasKalbertodt avatar LukasKalbertodt commented on May 20, 2024

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.

from confique.

ModProg avatar ModProg commented on May 20, 2024

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.

from confique.

LukasKalbertodt avatar LukasKalbertodt commented on May 20, 2024

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

from confique.

ModProg avatar ModProg commented on May 20, 2024

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.

from confique.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.