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

feat(Config): Add json config format option #698

Closed

Conversation

Profpatsch
Copy link
Contributor

In order to make it easier to generate gitit configuration, we add the ability for config files to be json values in addition to the custom config format parser.

This should be 100% backward-compatible, with the error messages being reasonably clear about the fallback mechanism.

Json strings, numbers and booleans are supported as-is, and the default section also works (sections are distinguished by their name being in [brackets]).

Potentially a bit more documentation might be needed.

@Profpatsch Profpatsch force-pushed the optional-json-config-format branch 4 times, most recently from 992ba0f to 4c22e9b Compare January 13, 2025 17:01
In order to make it easier to generate gitit configuration, we add the
ability for config files to be json values in addition to the custom
config format parser.

This should be 100% backward-compatible, with the error messages being
reasonably clear about the fallback mechanism.

Json strings, numbers and booleans are supported as-is, and the
default section also works (sections are distinguished by their name
being in `[brackets]`).

Potentially a bit more documentation might be needed.
@Profpatsch Profpatsch force-pushed the optional-json-config-format branch from 4c22e9b to ca08e51 Compare January 13, 2025 17:01
@jgm
Copy link
Owner

jgm commented Jan 13, 2025

Have you tested with a json version of the full default config file data/default.conf?

@jgm
Copy link
Owner

jgm commented Jan 13, 2025

I would think that the corresponding structure would use "GitHub": and not "[GitHub]":.
The brackets are needed in the ini format to indicate a group, but in JSON that isn't really needed.
What do you think?

@Profpatsch
Copy link
Contributor Author

Hm, I don’t think they are strictly needed, yes.

@Profpatsch
Copy link
Contributor Author

Have you tested with a json version of the full default config file data/default.conf?

Not yet, I did some tests with a subset but I’ll try and see what happens if I convert the whole file.

Another thought I had was to allow a subset of jsonc files (i.e. json files with #-comments) by filtering every line that starts with a #. This is supported by editors like vscode for example.
OTOH my use-case here is that this is mainly for easier config generation from nix.

@jgm
Copy link
Owner

jgm commented Jan 13, 2025

I'm not sure what I think about the proposal. It adds complexity to support an alternative config format, and complexity is, in general, bad. Is the value high enough to outweigh that? Generating a config file that consists of lines with key: value pairs does not seem very difficult and perhaps it's better to put the complexity outside fo gitit itself...

@Profpatsch
Copy link
Contributor Author

The biggest complexity here comes from having a non-standard config format imo; json is supported by every editor, with syntax checking and highlighting, can trivially be generated by every config tool (ansible, terraform, nixos …), and can support in-line documentation via a schema definition (vscode will natively look up a "$schema" key and display documentation from the linked schema file for example).

It’s a suggestion, I don’t have to necessarily upstream it since my downstream fork is gonna diverge a bunch anyway in the future.

@jgm
Copy link
Owner

jgm commented Jan 13, 2025

non-standard config format

This is a standard config format, https://en.wikipedia.org/wiki/INI_file , it's just not as popular now as it was when gitit was created. It's also extremely simple, both to parse and to write, and unlike JSON it allows comments, which are highly useful in config file.

(Yes, you can use a nonstandard JSON dialect that allows comments, but then you're using a non-standard config format!)

If I were creating gitit from scratch, I'd be tempted to use YAML, but I can't change the config format I'm using without breaking backwards compatibility for all existing users. And adding a format to what we have already is a net gain in complexity.

@Profpatsch Profpatsch closed this Jan 13, 2025
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

Successfully merging this pull request may close these issues.

2 participants