summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZack Hobson2009-07-21 10:53:43 -0700
committerZack Hobson2009-07-21 10:53:43 -0700
commit30239dc8f61b86335eb8a4de9bdbbe38b425aa0b (patch)
tree45688ede37e2a57bb7685d4bebb7e978b9e73bbe
parent538986dd21356b248806fc979998caa64cdedb50 (diff)
downloadhcl-30239dc8f61b86335eb8a4de9bdbbe38b425aa0b.tar.bz2
Added stop command, closes #5.
-rw-r--r--README.markdown11
-rw-r--r--lib/hcl.rb14
-rw-r--r--lib/hcl/day_entry.rb15
-rw-r--r--lib/hcl/task.rb1
4 files changed, 36 insertions, 5 deletions
diff --git a/README.markdown b/README.markdown
index 4067be9..f1e4ccc 100644
--- a/README.markdown
+++ b/README.markdown
@@ -20,16 +20,16 @@ NOTE This software is nowhere near complete. To try it out:
## Usage
-NOTE that /add/, /rm/ and /stop/ are not yet implemented.
+NOTE that /add/ and /rm/ are not yet implemented.
hcl show [date]
hcl tasks
hcl set <key> <value ...>
hcl unset <key>
hcl start (<task_alias> | <project_id> <task_id>) [msg]
+ hcl stop
hcl add (<task_alias> | <project_id> <task_id>) <duration> [msg]
hcl rm [entry_id]
- hcl stop [msg]
### Starting a Timer
@@ -54,6 +54,13 @@ identify a task, HCl supports task aliases:
$ hcl set task.xdev 1234 5678
$ hcl start xdev adding a new feature
+### Stopping a Timer
+
+The following command will stop a running timer (currently only one timer at
+a time is supported):
+
+ $ hcl stop
+
### Date Formats
Dates can be expressed in a variety of ways. See the [Chronic documentation][2]
diff --git a/lib/hcl.rb b/lib/hcl.rb
index 894c5ee..883ded6 100644
--- a/lib/hcl.rb
+++ b/lib/hcl.rb
@@ -122,12 +122,23 @@ EOM
puts "Started timer for #{task}"
end
+ def stop
+ entry = DayEntry.with_timer
+ if entry
+ entry.toggle
+ puts "Stopped #{entry}"
+ else
+ puts "No running timers found."
+ end
+ end
+
def show *args
date = args.empty? ? nil : Chronic.parse(args.join(' '))
total_hours = 0.0
DayEntry.all(date).each do |day|
# TODO more information and formatting options
- puts "\t#{as_hours day.hours}\t#{day.project} #{day.notes}"[0..78]
+ running = day.running? ? '(running) ' : ''
+ puts "\t#{as_hours day.hours}\t#{running}#{day.project} #{day.notes}"[0..78]
total_hours = total_hours + day.hours.to_f
end
puts "\t" + '-' * 13
@@ -145,7 +156,6 @@ EOM
end
# TODO implement the following commands
- alias stop not_implemented
alias add not_implemented
alias rm not_implemented
diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb
index e23f7e9..42f52f4 100644
--- a/lib/hcl/day_entry.rb
+++ b/lib/hcl/day_entry.rb
@@ -15,14 +15,27 @@ class HCl
def self.from_xml xml
doc = REXML::Document.new xml
Task.cache_tasks doc
- doc.root.elements.collect('day_entries/day_entry') do |day|
+ doc.root.elements.collect('*/day_entry') do |day|
new xml_to_hash(day)
end
end
+ def self.with_timer
+ all.detect {|t| t.running? }
+ end
+
+ def running?
+ !@data[:timer_started_at].nil? && !@data[:timer_started_at].empty?
+ end
+
def initialize *args
super
# TODO cache client/project names and ids
end
+
+ def toggle
+ DayEntry.get("daily/timer/#{id}")
+ self
+ end
end
end
diff --git a/lib/hcl/task.rb b/lib/hcl/task.rb
index 1a742ce..5923867 100644
--- a/lib/hcl/task.rb
+++ b/lib/hcl/task.rb
@@ -38,6 +38,7 @@ class HCl
EOT
days.first
end
+
end
end