mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 11:38:32 +02:00
Add prompt for --change-time
This commit is contained in:
parent
3f7dd19d90
commit
0f791cf69a
3 changed files with 79 additions and 37 deletions
|
@ -261,32 +261,30 @@ class Journal:
|
||||||
for entry in entries_to_delete:
|
for entry in entries_to_delete:
|
||||||
self.entries.remove(entry)
|
self.entries.remove(entry)
|
||||||
|
|
||||||
def prompt_delete_entries(self):
|
|
||||||
"""Prompts for deletion of each of the entries in a journal.
|
|
||||||
Returns the entries the user wishes to delete."""
|
|
||||||
|
|
||||||
to_delete = []
|
|
||||||
|
|
||||||
def ask_delete(entry):
|
|
||||||
return yesno(
|
|
||||||
f"Delete entry '{entry.pprint(short=True)}'?",
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
for entry in self.entries:
|
|
||||||
if ask_delete(entry):
|
|
||||||
to_delete.append(entry)
|
|
||||||
|
|
||||||
return to_delete
|
|
||||||
|
|
||||||
def change_date_entries(self, date):
|
def change_date_entries(self, date):
|
||||||
"""Changes entry dates to given date."""
|
"""Changes entry dates to given date."""
|
||||||
|
|
||||||
date = time.parse(date)
|
date = time.parse(date)
|
||||||
|
|
||||||
for entry in self.entries:
|
for entry in self.entries:
|
||||||
entry.date = date
|
entry.date = date
|
||||||
|
|
||||||
|
def prompt_action_entries(self, message):
|
||||||
|
"""Prompts for action for each entry in a journal, using given message.
|
||||||
|
Returns the entries the user wishes to apply the action on."""
|
||||||
|
to_act = []
|
||||||
|
|
||||||
|
def ask_action(entry):
|
||||||
|
return yesno(
|
||||||
|
f"{message} '{entry.pprint(short=True)}'?",
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
for entry in self.entries:
|
||||||
|
if ask_action(entry):
|
||||||
|
to_act.append(entry)
|
||||||
|
|
||||||
|
return to_act
|
||||||
|
|
||||||
def new_entry(self, raw, date=None, sort=True):
|
def new_entry(self, raw, date=None, sort=True):
|
||||||
"""Constructs a new entry from some raw text input.
|
"""Constructs a new entry from some raw text input.
|
||||||
If a date is given, it will parse and use this, otherwise scan for a date in the input first."""
|
If a date is given, it will parse and use this, otherwise scan for a date in the input first."""
|
||||||
|
|
23
jrnl/jrnl.py
23
jrnl/jrnl.py
|
@ -329,7 +329,7 @@ def _delete_search_results(journal, old_entries, **kwargs):
|
||||||
if not journal.entries:
|
if not journal.entries:
|
||||||
raise JrnlException(Message(MsgText.NothingToDelete, MsgType.ERROR))
|
raise JrnlException(Message(MsgText.NothingToDelete, MsgType.ERROR))
|
||||||
|
|
||||||
entries_to_delete = journal.prompt_delete_entries()
|
entries_to_delete = journal.prompt_action_entries("Delete entry")
|
||||||
|
|
||||||
if entries_to_delete:
|
if entries_to_delete:
|
||||||
journal.entries = old_entries
|
journal.entries = old_entries
|
||||||
|
@ -338,19 +338,28 @@ def _delete_search_results(journal, old_entries, **kwargs):
|
||||||
journal.write()
|
journal.write()
|
||||||
|
|
||||||
|
|
||||||
def _change_time_search_results(args, journal, old_entries, **kwargs):
|
def _change_time_search_results(args, journal, old_entries, no_prompt=False, **kwargs):
|
||||||
if not journal.entries:
|
if not journal.entries:
|
||||||
raise JrnlException(Message(MsgText.NothingToModify, MsgType.WARNING))
|
raise JrnlException(Message(MsgText.NothingToModify, MsgType.WARNING))
|
||||||
|
|
||||||
# separate entries we are not editing
|
# separate entries we are not editing
|
||||||
other_entries = _other_entries(journal, old_entries)
|
other_entries = _other_entries(journal, old_entries)
|
||||||
|
|
||||||
date = time.parse(args.change_time)
|
if no_prompt:
|
||||||
journal.change_date_entries(date)
|
entries_to_change = journal.entries
|
||||||
|
else:
|
||||||
|
entries_to_change = journal.prompt_action_entries("Change time")
|
||||||
|
|
||||||
journal.entries += other_entries
|
if entries_to_change:
|
||||||
journal.sort()
|
other_entries += [e for e in journal.entries if e not in entries_to_change]
|
||||||
journal.write()
|
journal.entries = entries_to_change
|
||||||
|
|
||||||
|
date = time.parse(args.change_time)
|
||||||
|
journal.change_date_entries(date)
|
||||||
|
|
||||||
|
journal.entries += other_entries
|
||||||
|
journal.sort()
|
||||||
|
journal.write()
|
||||||
|
|
||||||
|
|
||||||
def _display_search_results(args, journal, **kwargs):
|
def _display_search_results(args, journal, **kwargs):
|
||||||
|
|
|
@ -4,7 +4,8 @@ Feature: Change entry times in journal
|
||||||
And we use the password "test" if prompted
|
And we use the password "test" if prompted
|
||||||
When we run "jrnl -1"
|
When we run "jrnl -1"
|
||||||
Then the output should contain "2020-09-24 09:14 The third entry finally"
|
Then the output should contain "2020-09-24 09:14 The third entry finally"
|
||||||
When we run "jrnl -1 --change-time '2022-04-23 10:30'"
|
When we run "jrnl -1 --change-time '2022-04-23 10:30'" and enter
|
||||||
|
Y
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-29 11:11 Entry the first.
|
2020-08-29 11:11 Entry the first.
|
||||||
|
@ -18,6 +19,28 @@ Feature: Change entry times in journal
|
||||||
| basic_folder.yaml |
|
| basic_folder.yaml |
|
||||||
# | basic_dayone.yaml | @todo
|
# | basic_dayone.yaml | @todo
|
||||||
|
|
||||||
|
Scenario Outline: Change flag changes prompted entries
|
||||||
|
Given we use the config "<config_file>"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl -1"
|
||||||
|
Then the output should contain "2020-09-24 09:14 The third entry finally"
|
||||||
|
When we run "jrnl --change-time '2022-04-23 10:30'" and enter
|
||||||
|
Y
|
||||||
|
N
|
||||||
|
Y
|
||||||
|
When we run "jrnl -99 --short"
|
||||||
|
Then the output should be
|
||||||
|
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||||
|
2022-04-23 10:30 Entry the first.
|
||||||
|
2022-04-23 10:30 The third entry finally after weeks without writing.
|
||||||
|
|
||||||
|
Examples: Configs
|
||||||
|
| config_file |
|
||||||
|
| basic_onefile.yaml |
|
||||||
|
| basic_encrypted.yaml |
|
||||||
|
| basic_folder.yaml |
|
||||||
|
# | basic_dayone.yaml | @todo
|
||||||
|
|
||||||
|
|
||||||
Scenario Outline: Change time flag with nonsense input changes nothing
|
Scenario Outline: Change time flag with nonsense input changes nothing
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
|
@ -38,7 +61,8 @@ Feature: Change entry times in journal
|
||||||
|
|
||||||
Scenario Outline: Change time flag with tag only changes tagged entries
|
Scenario Outline: Change time flag with tag only changes tagged entries
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
When we run "jrnl --change-time '2022-04-23 10:30' @ipsum"
|
When we run "jrnl --change-time '2022-04-23 10:30' @ipsum" and enter
|
||||||
|
Y
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||||
|
@ -54,7 +78,9 @@ Feature: Change entry times in journal
|
||||||
|
|
||||||
Scenario Outline: Change time flag with multiple tags changes all entries matching any of the tags
|
Scenario Outline: Change time flag with multiple tags changes all entries matching any of the tags
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
When we run "jrnl --change-time '2022-04-23 10:30' @ipsum @tagthree"
|
When we run "jrnl --change-time '2022-04-23 10:30' @ipsum @tagthree" and enter
|
||||||
|
Y
|
||||||
|
Y
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||||
|
@ -70,7 +96,8 @@ Feature: Change entry times in journal
|
||||||
|
|
||||||
Scenario Outline: Change time flag with -and changes boolean AND of tagged entries
|
Scenario Outline: Change time flag with -and changes boolean AND of tagged entries
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
When we run "jrnl --change-time '2022-04-23 10:30' -and @tagone @tagtwo"
|
When we run "jrnl --change-time '2022-04-23 10:30' -and @tagone @tagtwo" and enter
|
||||||
|
Y
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||||
|
@ -86,7 +113,8 @@ Feature: Change entry times in journal
|
||||||
|
|
||||||
Scenario Outline: Change time flag with -not does not change entries from given tag
|
Scenario Outline: Change time flag with -not does not change entries from given tag
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
When we run "jrnl --change-time '2022-04-23 10:30' @tagone -not @ipsum"
|
When we run "jrnl --change-time '2022-04-23 10:30' @tagone -not @ipsum" and enter
|
||||||
|
Y
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-29 11:11 Entry the first.
|
2020-08-29 11:11 Entry the first.
|
||||||
|
@ -102,7 +130,8 @@ Feature: Change entry times in journal
|
||||||
|
|
||||||
Scenario Outline: Change time flag with -from search operator only changes entries since that date
|
Scenario Outline: Change time flag with -from search operator only changes entries since that date
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
When we run "jrnl --change-time '2022-04-23 10:30' -from 2020-09-01"
|
When we run "jrnl --change-time '2022-04-23 10:30' -from 2020-09-01" and enter
|
||||||
|
Y
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-29 11:11 Entry the first.
|
2020-08-29 11:11 Entry the first.
|
||||||
|
@ -118,7 +147,9 @@ Feature: Change entry times in journal
|
||||||
|
|
||||||
Scenario Outline: Change time flag with -to only changes entries up to specified date
|
Scenario Outline: Change time flag with -to only changes entries up to specified date
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
When we run "jrnl --change-time '2022-04-23 10:30' -to 2020-08-31"
|
When we run "jrnl --change-time '2022-04-23 10:30' -to 2020-08-31" and enter
|
||||||
|
Y
|
||||||
|
Y
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-09-24 09:14 The third entry finally after weeks without writing.
|
2020-09-24 09:14 The third entry finally after weeks without writing.
|
||||||
|
@ -134,7 +165,8 @@ Feature: Change entry times in journal
|
||||||
|
|
||||||
Scenario Outline: Change time flag with -starred only changes starred entries
|
Scenario Outline: Change time flag with -starred only changes starred entries
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
When we run "jrnl --change-time '2022-04-23 10:30' -starred"
|
When we run "jrnl --change-time '2022-04-23 10:30' -starred" and enter
|
||||||
|
Y
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-29 11:11 Entry the first.
|
2020-08-29 11:11 Entry the first.
|
||||||
|
@ -150,7 +182,8 @@ Feature: Change entry times in journal
|
||||||
|
|
||||||
Scenario Outline: Change time flag with -contains only changes entries containing expression
|
Scenario Outline: Change time flag with -contains only changes entries containing expression
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
When we run "jrnl --change-time '2022-04-23 10:30' -contains dignissim"
|
When we run "jrnl --change-time '2022-04-23 10:30' -contains dignissim" and enter
|
||||||
|
Y
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||||
|
@ -167,8 +200,10 @@ Feature: Change entry times in journal
|
||||||
Scenario Outline: Change time flag with no enties specified changes nothing
|
Scenario Outline: Change time flag with no enties specified changes nothing
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
And we use the password "test" if prompted
|
And we use the password "test" if prompted
|
||||||
When we run "jrnl --change-time"
|
When we run "jrnl --change-time" and enter
|
||||||
Then the output should contain "No entries to modify"
|
N
|
||||||
|
N
|
||||||
|
N
|
||||||
When we run "jrnl -99 --short"
|
When we run "jrnl -99 --short"
|
||||||
Then the output should be
|
Then the output should be
|
||||||
2020-08-29 11:11 Entry the first.
|
2020-08-29 11:11 Entry the first.
|
||||||
|
|
Loading…
Add table
Reference in a new issue