lib/timetrap/cli.rb in timetrap-1.8.3 vs lib/timetrap/cli.rb in timetrap-1.8.4

- old
+ new

@@ -51,11 +51,12 @@ ical, csv, json, ids, factor, and text (default). Documentation on defining custom formats can be found in the README included in this distribution. - * edit - Alter an entry's note, start, or end time. Defaults to the active entry. + * edit - Alter an entry's note, start, or end time. Defaults to the active + entry. Defaults to the last entry to be checked out of if no entry is active. usage: t edit [--id ID] [--start TIME] [--end TIME] [--append] [NOTES] -i, --id <id:i> Alter entry with id <id> instead of the running entry -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 @@ -196,17 +197,28 @@ Config.configure! puts "Config file is at #{Config::PATH.inspect}" end def edit - entry = args['-i'] ? Entry[args['-i']] : Timer.active_entry + entry = case + when args['-i'] + warn "Editing entry with id #{args['-i'].inspect}" + Entry[args['-i']] + when Timer.active_entry + warn "Editing running entry" + Timer.active_entry + when Timer.last_checkout + warn "Editing last entry you checked out of" + Timer.last_checkout + end + unless entry - warn "can't find entry" + warn "Can't find entry" return - else - warn "editing entry ##{entry.id.inspect}" end + warn "" + entry.update :start => args['-s'] if args['-s'] =~ /.+/ entry.update :end => args['-e'] if args['-e'] =~ /.+/ # update sheet if args['-m'] =~ /.+/ @@ -222,10 +234,12 @@ if args['-z'] note = [entry.note, note].join(Config['append_notes_delimiter']) end entry.update :note => note end + + puts format_entries(entry) end def backend exec "sqlite3 #{DB_NAME}" end @@ -287,11 +301,11 @@ def display entries = selected_entries.order(:start).all if entries == [] warn "No entries were selected to display." else - puts load_formatter(args['-f'] || Config['default_formatter']).new(entries).output + puts format_entries(entries) end end def sheet sheet = unused_args @@ -381,9 +395,13 @@ def ask_user question return true if args['-y'] $stderr.print question $stdin.gets =~ /\Aye?s?\Z/i + end + + def format_entries(entries) + load_formatter(args['-f'] || Config['default_formatter']).new(Array(entries)).output end end end