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

Re-serialisation maintaining comments and whitespace #22

Open
Tatskaari opened this issue Oct 29, 2020 · 1 comment
Open

Re-serialisation maintaining comments and whitespace #22

Tatskaari opened this issue Oct 29, 2020 · 1 comment

Comments

@Tatskaari
Copy link

Tatskaari commented Oct 29, 2020

We use this library to parse our config for please

One thing I'm trying to figure out is updating config automatically for our users. For example, if they want to add language support to their project, I want to be able to plz init java and that will add:

[java]
javac = /opt/java/bin/javac

I was thinking it wouldn't be too crazy if we maintain the original token stream. We can detect any changes/new non-zero entries in the struct, and append these to the first instance of the relevant section (i.e. [java]).

I just thought I would open up an issue here and see if this is something you'd be interested in having upstream.

@speter
Copy link
Contributor

speter commented Nov 3, 2020

Thanks for the feedback. Writing/updating gcfg files is something that I would be interested in having upstream. (Historically there was a ticket for this back when the project was on Google Code, but it wasn't migrated here, sorry.)

However I'm not sure if re-serialization is possible; it seems hard to check for changed values, considering the fact that Go doesn't provide a standardized way of checking for equality. (The closest we have is reflect.DeepEqual() but it is not guaranteed to work with user-defined types.) What could be done more easily is to have a function that takes a section name, subsection name, variable name and new value, and updates that value.

Even then, there are some tricky issues with the handling of comments; changing a value may make a comment invalid, and also keeping indenting of comments is non-trivial esp. for multilanguage files. One way to approach these issues is to check what git config does in such situations.

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