diff --git a/lib/hcl.rb b/lib/hcl.rb index f5889ab..e045328 100644 --- a/lib/hcl.rb +++ b/lib/hcl.rb @@ -39,21 +39,26 @@ def self.command *args end def run - if @command - if respond_to? @command - result = send @command, *@args - if not result.nil? - if result.respond_to? :to_a - puts result.to_a.join(', ') - elsif result.respond_to? :to_s - puts result + begin + if @command + if respond_to? @command + result = send @command, *@args + if not result.nil? + if result.respond_to? :to_a + puts result.to_a.join(', ') + elsif result.respond_to? :to_s + puts result + end end + else + raise UnknownCommand, "unrecognized command `#{@command}'" end else - raise UnknownCommand, "unrecognized command `#{@command}'" + show end - else - show + rescue TimesheetResource::Failure => e + puts "Internal failure. #{e}" + exit 1 end end diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb index 9948250..874273f 100644 --- a/lib/hcl/day_entry.rb +++ b/lib/hcl/day_entry.rb @@ -2,6 +2,7 @@ class HCl class DayEntry < TimesheetResource include Utility + # Get the time sheet entries for a given day. If no date is provided # defaults to today. def self.all date = nil @@ -15,6 +16,7 @@ def to_s def self.from_xml xml doc = REXML::Document.new xml + raise Failure, "No root node in XML document: #{xml}" if doc.root.nil? Task.cache_tasks doc doc.root.elements.collect('//day_entry') do |day| new xml_to_hash(day) diff --git a/lib/hcl/timesheet_resource.rb b/lib/hcl/timesheet_resource.rb index 381fe53..3072d07 100644 --- a/lib/hcl/timesheet_resource.rb +++ b/lib/hcl/timesheet_resource.rb @@ -1,5 +1,7 @@ class HCl class TimesheetResource + class Failure < Exception; end + def self.configure opts = nil if opts self.login = opts['login']