From 329d889fc38c881efc176b3df3ccb5b62c6f1e96 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Sat, 23 Apr 2022 20:54:06 -0500 Subject: [PATCH] Add warning when --change-time used with no matching entries --- jrnl/jrnl.py | 3 +++ jrnl/messages.py | 4 ++++ tests/bdd/features/change_time.feature | 1 + 3 files changed, 8 insertions(+) diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 439237c6..43800ddf 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -339,6 +339,9 @@ def _delete_search_results(journal, old_entries, **kwargs): def _change_time_search_results(args, journal, old_entries, **kwargs): + if not journal.entries: + raise JrnlException(Message(MsgText.NothingToModify, MsgType.WARNING)) + # separate entries we are not editing other_entries = _other_entries(journal, old_entries) diff --git a/jrnl/messages.py b/jrnl/messages.py index e6a1933a..7e7bc205 100644 --- a/jrnl/messages.py +++ b/jrnl/messages.py @@ -130,6 +130,10 @@ class MsgText(Enum): No entries to delete, because the search returned no results """ + NothingToModify = """ + No entries to modify, because the search returned no results + """ + class Message(NamedTuple): text: MsgText diff --git a/tests/bdd/features/change_time.feature b/tests/bdd/features/change_time.feature index a4fdb403..3379fe70 100644 --- a/tests/bdd/features/change_time.feature +++ b/tests/bdd/features/change_time.feature @@ -22,6 +22,7 @@ Feature: Change entry times in journal Scenario Outline: Change time flag with nonsense input changes nothing Given we use the config "" When we run "jrnl --change-time now asdfasdf" + Then the output should contain "No entries to modify" When we run "jrnl -99 --short" Then the output should be 2020-08-29 11:11 Entry the first.