lib/timetrap/cli.rb in timetrap-1.15.2 vs lib/timetrap/cli.rb in timetrap-1.15.4
- old
+ new
@@ -69,10 +69,11 @@
-s, --start <time:qs> Change the start time to <time>
-e, --end <time:qs> Change the end time to <time>
-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.
usage: t in [--at TIME] [NOTES]
-a, --at <time:qs> Use this time instead of now
@@ -245,18 +246,22 @@
end
entry.update :sheet => args['-m']
end
if Config['note_editor']
- if args['-z']
+ if args['-c']
+ 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'])
end
entry.update :note => note
@@ -322,19 +327,23 @@
end
def out
if Config['auto_checkout']
stopped = Timer.stop_all(args['-a']).each do |checked_out_of|
- warn "Checked out of sheet #{checked_out_of.sheet.inspect}."
+ note = Timer.last_checkout.note
+ entry = note_blank?(note) ? Timer.last_checkout.id : note.inspect
+ warn "Checked out of entry #{entry} in sheet #{checked_out_of.sheet.inspect}."
end
if stopped.empty?
warn "No running entries to stop."
end
else
sheet = sheet_name_from_string(unused_args)
if Timer.stop sheet, args['-a']
- warn "Checked out of sheet #{sheet.inspect}."
+ note = Timer.last_checkout.note
+ entry = note_blank?(note) ? Timer.last_checkout.id : note.inspect
+ warn "Checked out of entry #{entry} in sheet #{sheet.inspect}."
else
warn "No running entry on sheet #{sheet.inspect}."
end
end
end
@@ -388,12 +397,14 @@
end
Timer.current_sheet = sheet
if Timer.last_sheet == sheet
warn "Already on sheet #{sheet.inspect}"
- else
+ elsif Entry.sheets.include?(sheet)
warn "Switching to sheet #{sheet.inspect}"
+ else
+ warn "Switching to sheet #{sheet.inspect} (new sheet)"
end
end
def list
sheets = ([Timer.current_sheet] | Entry.sheets).map do |sheet|
@@ -474,9 +485,13 @@
args['-e'] = end_of_month.to_s
display
end
private
+
+ def note_blank?(note)
+ note.inspect.to_s.gsub('"', '').strip.size.zero?
+ end
def unused_args
args.unused.join(' ')
end