jrnl-org / jrnl

Collect your thoughts and notes without leaving the command line.
https://jrnl.sh
GNU General Public License v3.0
6.49k stars 523 forks source link

Refactor configuration retrieval/writing #1102

Open micahellison opened 3 years ago

micahellison commented 3 years ago

Feature Request

Use Case/Motivation

Down the road, we'd like to allow users to modify the config from the command line (#330, #1068) but currently our configuration code is a bit finnicky.

We also currently have a process in our code that is constantly rewriting the config file, when it probably shouldn't be.

And it'd be very nice to support and preserve detailed default comments in the config file (#946).

And, as we come up with new config keys and deprecate old ones, it would be nice to have defaults for various keys that never need to be expressed in the config file, rather than constantly adding a "config stew" of keys.

To resolve this issues, we're probably going to want to:

micahellison commented 2 years ago

It looks pydantic could be promising for validating the config file when jrnl first loads.

micahellison commented 2 years ago

For #946 to work using ruamel.yaml, we'll need to deal with two different representations of the configuration:

One of the big innovations of ruamel seems to be around modifying just part of the YAML at once. We could take that approach, or keep loading the whole thing into memory then dumping it back. I don't think the performance implications are going to be significant either way so my impulse is to focus instead on maintainability wherever possible.

micahellison commented 1 year ago

This refactor should also at least leave open the ability to read different versions of the config file, and probably some sort of versioning applied to the default values when they're not in the config file.