Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add edit option to clear note #205

Merged
merged 1 commit into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/timetrap/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module CLI
-z, --append Append to the current note instead of replacing it
the delimiter between appended notes is
configurable (see configure)
-c, --clear Allow an empty note, can be used to clear existing notes
-m, --move <sheet> Move to another sheet

* in - Start the timer for the current timesheet.
Expand Down Expand Up @@ -247,14 +248,18 @@ def edit
end

if Config['note_editor']
if args['-z']
if args['-c']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥦 If -c is provided it will clear even if a note is provided. In other words clearing is prioritized.

entry.update :note => ''
elsif args['-z']
note = [entry.note, get_note_from_external_editor].join(Config['append_notes_delimiter'])
entry.update :note => note
elsif editing_a_note?
entry.update :note => get_note_from_external_editor(entry.note)
end
else
if unused_args =~ /.+/
if args['-c']
entry.update :note => ''
elsif unused_args =~ /.+/
note = unused_args
if args['-z']
note = [entry.note, note].join(Config['append_notes_delimiter'])
Expand Down
24 changes: 24 additions & 0 deletions spec/timetrap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ def invoke command
expect(Timetrap::Timer.active_entry.note).to eq 'running entry//new//more'
end

it "should allow clearing the description of the active period" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥦 Specs similar to --append specs.

expect(Timetrap::Timer.active_entry.note).to eq 'running entry'
invoke 'edit --clear'
expect(Timetrap::Timer.active_entry.note).to eq ''
invoke 'edit running entry'
expect(Timetrap::Timer.active_entry.note).to eq 'running entry'
invoke 'edit -c'
expect(Timetrap::Timer.active_entry.note).to eq ''
end

it "should edit the start time of the active period" do
invoke 'edit --start "yesterday 10am"'
expect(Timetrap::Timer.active_entry.start).to eq Chronic.parse("yesterday 10am")
Expand Down Expand Up @@ -340,6 +350,20 @@ def invoke command
expect(Timetrap::Timer.active_entry.note).to eq 'running entry//appended in editor'
end
end

context "clearing" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥦 Specs with the editor

it "should clear the last entry with -c" do
expect(Timetrap::Timer.active_entry.note).to eq 'running entry'
invoke "edit -c"
expect(Timetrap::Timer.active_entry.note).to eq ''
end

it "should clear the last entry with --clear" do
expect(Timetrap::Timer.active_entry.note).to eq 'running entry'
invoke "edit --clear"
expect(Timetrap::Timer.active_entry.note).to eq ''
end
end
end
end

Expand Down