From d94325127f01f5d0b024a1cbd30350a68249754c Mon Sep 17 00:00:00 2001 From: Jonathan van der Steege Date: Sat, 7 Jan 2023 20:46:12 +0100 Subject: [PATCH] Update version key in config file after version changes (#1646) --- jrnl/install.py | 9 +++++++++ tests/bdd/features/config_file.feature | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/jrnl/install.py b/jrnl/install.py index b5ec636e..5ae14f36 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -9,6 +9,7 @@ import sys from rich.pretty import pretty_repr +from jrnl import __version__ from jrnl.config import DEFAULT_JOURNAL_KEY from jrnl.config import get_config_path from jrnl.config import get_default_config @@ -32,12 +33,20 @@ def upgrade_config(config_data: dict, alt_config_path: str | None = None) -> Non """Checks if there are keys missing in a given config dict, and if so, updates the config file accordingly. This essentially automatically ports jrnl installations if new config parameters are introduced in later versions. + Also checks for existence of and difference in version number between config dict and current jrnl version, + and if so, update the config file accordingly. Supply alt_config_path if using an alternate config through --config-file.""" default_config = get_default_config() missing_keys = set(default_config).difference(config_data) if missing_keys: for key in missing_keys: config_data[key] = default_config[key] + + different_version = (config_data["version"] != __version__) + if different_version: + config_data["version"] = __version__ + + if missing_keys or different_version: save_config(config_data, alt_config_path) config_path = alt_config_path if alt_config_path else get_config_path() print_msg( diff --git a/tests/bdd/features/config_file.feature b/tests/bdd/features/config_file.feature index 3369e666..2d2aade0 100644 --- a/tests/bdd/features/config_file.feature +++ b/tests/bdd/features/config_file.feature @@ -133,3 +133,9 @@ Feature: Multiple journals Given we use the config "multiple.yaml" When we run "jrnl --config-override highlight false" Then the output should not contain "There is at least one duplicate key in your configuration file" + + Scenario: Update version number in config file when running newer version + Given we use the config "format_md.yaml" + When we run "jrnl -1" + Then the output should contain "Configuration updated to newest version at" + And the version in the config file should be up-to-date \ No newline at end of file