diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index aa26d1e1..5e112353 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -109,6 +109,19 @@ def _is_write_mode(args, config, **kwargs): ): write_mode = False + # If -not is set but we are not searching, throw an error + if write_mode and args.excluded: + raise JrnlException( + Message( + MsgText.InvalidArgumentUsage, + MsgType.NORMAL, + { + "arg": "-not", + "msg": "expected another search parameter like -on, -contains, etc.", + }, + ) + ) + return write_mode diff --git a/jrnl/messages.py b/jrnl/messages.py index 34f45e7d..40eb2331 100644 --- a/jrnl/messages.py +++ b/jrnl/messages.py @@ -134,6 +134,9 @@ class MsgText(Enum): No entries to modify, because the search returned no results """ + # --- Usage --- # + InvalidArgumentUsage = "Invalid usage of {arg}: {msg}" + class Message(NamedTuple): text: MsgText diff --git a/tests/bdd/features/search.feature b/tests/bdd/features/search.feature index 44e8dc6d..64705e6b 100644 --- a/tests/bdd/features/search.feature +++ b/tests/bdd/features/search.feature @@ -292,3 +292,11 @@ Feature: Searching in a journal 2013-06-17 20:38 This entry has a location. 2013-07-17 11:38 This entry is starred! + + Scenario: Using -not without other search parameters should not open editor + Given we use the config "editor.yaml" + And we write nothing to the editor if opened + And we use the password "test" if prompted + When we run "jrnl -not @tag" + Then the error output should contain "Invalid usage of -not" + And the editor should not have been called