mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Update version key in config file after version changes (#1646)
This commit is contained in:
parent
fe08cfd3ab
commit
d94325127f
2 changed files with 15 additions and 0 deletions
|
@ -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(
|
||||
|
|
|
@ -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
|
Loading…
Add table
Reference in a new issue