lib/timetrap/cli.rb in timetrap-1.3.0 vs lib/timetrap/cli.rb in timetrap-1.4.0

- old
+ new

@@ -52,12 +52,13 @@ usage: t switch TIMESHEET * week - shortcut for display with start date set to monday of this week usage: t week [--ids] [--end DATE] [--format FMT] [SHEET | all] OTHER OPTIONS - -h, --help Display this help - -r, --round Round output to 15 minute start and end times. + -h, --help Display this help + -r, --round Round output to 15 minute start and end times. + -y, --yes Noninteractive, assume yes as answer to all prompts Submit bugs and feature requests to http://github.com/samg/timetrap/issues EOF def parse arguments @@ -93,13 +94,11 @@ Timetrap::Entry.round = true if args['-r'] end def archive ee = selected_entries - out = "Archive #{ee.count} entries? " - print out - if $stdin.gets =~ /\Aye?s?\Z/i + if ask_user "Archive #{ee.count} entries? " ee.all.each do |e| next unless e.end e.update :sheet => "_#{e.sheet}" end else @@ -134,21 +133,19 @@ def kill if e = Entry[args['-i']] out = "are you sure you want to delete entry #{e.id}? " out << "(#{e.note}) " if e.note.to_s =~ /.+/ - print out - if $stdin.gets =~ /\Aye?s?\Z/i + if ask_user out e.destroy say "it's dead" else say "will not kill" end elsif (sheets = Entry.map{|e| e.sheet }.uniq).include?(sheet = unused_args) victims = Entry.filter(:sheet => sheet).count - print "are you sure you want to delete #{victims} entries on sheet #{sheet.inspect}? " - if $stdin.gets =~ /\Aye?s?\Z/i + if ask_user "are you sure you want to delete #{victims} entries on sheet #{sheet.inspect}? " Timetrap.kill_sheet sheet say "killed #{victims} entries" else say "will not kill" end @@ -227,9 +224,15 @@ private def unused_args args.unused.join(' ') + end + + def ask_user question + return true if args['-y'] + print question + $stdin.gets =~ /\Aye?s?\Z/i end end end