summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/hcl.rb27
-rw-r--r--lib/hcl/day_entry.rb2
-rw-r--r--lib/hcl/timesheet_resource.rb2
3 files changed, 20 insertions, 11 deletions
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 @@ class HCl
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 @@ class HCl
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']