mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Store multiple -contains arguments (OR default).
Allow multiple occurrences of the -contains argument to be stored in a list. Previously, only the last occurrence was considered. Additionally, the behavior has been modified to default to OR logic, meaning that if multiple -contains arguments are provided, entries matching any of them will be included in the results.
This commit is contained in:
parent
0aefdb3f21
commit
edff5f861c
2 changed files with 8 additions and 4 deletions
|
@ -265,6 +265,7 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
|
||||||
reading.add_argument(
|
reading.add_argument(
|
||||||
"-contains",
|
"-contains",
|
||||||
dest="contains",
|
dest="contains",
|
||||||
|
action="append",
|
||||||
metavar="TEXT",
|
metavar="TEXT",
|
||||||
help="Show entries containing specific text (put quotes around text with "
|
help="Show entries containing specific text (put quotes around text with "
|
||||||
"spaces)",
|
"spaces)",
|
||||||
|
|
|
@ -246,7 +246,7 @@ class Journal:
|
||||||
exclude_starred=False,
|
exclude_starred=False,
|
||||||
exclude_tagged=False,
|
exclude_tagged=False,
|
||||||
strict=False,
|
strict=False,
|
||||||
contains=None,
|
contains=[],
|
||||||
exclude=[],
|
exclude=[],
|
||||||
):
|
):
|
||||||
"""Removes all entries from the journal that don't match the filter.
|
"""Removes all entries from the journal that don't match the filter.
|
||||||
|
@ -276,7 +276,7 @@ class Journal:
|
||||||
return 0 < len([tag for tag in tags if tag in excluded_tags])
|
return 0 < len([tag for tag in tags if tag in excluded_tags])
|
||||||
|
|
||||||
if contains:
|
if contains:
|
||||||
contains_lower = contains.casefold()
|
contains_lower = [substring.casefold() for substring in contains]
|
||||||
|
|
||||||
# Create datetime object for comparison below
|
# Create datetime object for comparison below
|
||||||
# this approach allows various formats
|
# this approach allows various formats
|
||||||
|
@ -298,8 +298,11 @@ class Journal:
|
||||||
and (
|
and (
|
||||||
not contains
|
not contains
|
||||||
or (
|
or (
|
||||||
contains_lower in entry.title.casefold()
|
any(
|
||||||
or contains_lower in entry.body.casefold()
|
substring in entry.title.casefold()
|
||||||
|
or substring in entry.body.casefold()
|
||||||
|
for substring in contains_lower
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Reference in a new issue