lib/timetrap/cli.rb in timetrap-1.6.0 vs lib/timetrap/cli.rb in timetrap-1.6.1
- old
+ new
@@ -49,12 +49,10 @@
-z, --append Append to the current note instead of replacing it
the delimiter between appended notes is
configurable (see configure)
-m, --move <sheet> Move to another sheet
- * format - Deprecated: alias for display.
-
* in - Start the timer for the current timesheet.
usage: t in [--at TIME] [NOTES]
-a, --at <time:qs> Use this time instead of now
* kill - Delete a timesheet or an entry.
@@ -69,17 +67,14 @@
* out - Stop the timer for the a timesheet.
usage: t out [--at TIME] [TIMESHEET]
-a, --at <time:qs> Use this time instead of now
- * running - Deprecated: alias for now.
+ * sheet - Switch to a timesheet creating it if necessary. When no sheet is
+ specified list all sheets.
+ usage: t sheet [TIMESHEET]
- * sheet - Switch to a timesheet creating it if necessary.
- usage: t sheet TIMESHEET
-
- * switch - Deprecated: renamed to sheet.
-
* 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
@@ -119,24 +114,40 @@
def commands
Timetrap::CLI::USAGE.scan(/\* \w+/).map{|s| s.gsub(/\* /, '')}
end
+ def deprecated_commands
+ {
+ 'switch' => 'sheet',
+ 'running' => 'now',
+ 'format' => 'display'
+ }
+ end
+
def invoke_command_if_valid
command = args.unused.shift
set_global_options
case (valid = commands.select{|name| name =~ %r|^#{command}|}).size
- when 0 then puts "Invalid command: #{command}"
+ when 1 then send valid[0]
else
- if command
- send valid[0]
- else
- puts USAGE
- end
+ handle_invalid_command(command)
end
end
+ def handle_invalid_command(command)
+ if !command
+ puts USAGE
+ elsif mapping = deprecated_commands.detect{|(k,v)| k =~ %r|^#{command}|}
+ deprecated, current = *mapping
+ warn "The #{deprecated.inspect} command is deprecated in favor of #{current.inspect}. Sorry for the inconvenience."
+ send current
+ else
+ warn "Invalid command: #{command.inspect}"
+ end
+ end
+
# currently just sets whether output should be rounded to 15 min intervals
def set_global_options
Timetrap::Entry.round = true if args['-r']
end
@@ -244,24 +255,21 @@
warn "No entries were selected to display."
else
puts fmt_klass.new(entries).output
end
end
- alias_method :format, :display
def sheet
sheet = unused_args
unless sheet =~ /.+/
- warn "No sheet specified"
+ list
else
Timer.current_sheet = sheet
warn "Switching to sheet #{sheet.inspect}"
end
end
- alias_method :switch, :sheet
-
def list
sheets = ([Timer.current_sheet] | Entry.sheets).map do |sheet|
sheet_atts = {:total => 0, :running => 0, :today => 0}
entries = Timetrap::Entry.filter(:sheet => sheet)
if entries.empty?
@@ -299,10 +307,9 @@
out << "#{entry[:sheet]}: #{format_duration(entry.start, entry.end_or_now)}".gsub(/ /, ' ')
out << " (#{entry.note})" if entry.note =~ /.+/
puts out
end
end
- alias_method :running, :display
def week
args['-s'] = Date.today.wday == 1 ? Date.today.to_s : Date.parse(Chronic.parse(%q(last monday)).to_s).to_s
display
end