Editor no longer opens when -not is used without search flags

This commit is contained in:
apainintheneck 2022-05-22 17:20:06 -07:00
parent fd8d64098f
commit 471b1d1dd2
3 changed files with 24 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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