diff options
| -rw-r--r-- | README.markdown | 36 | ||||
| -rw-r--r-- | lib/hcl.rb | 46 | ||||
| -rw-r--r-- | lib/hcl/task.rb | 8 |
3 files changed, 76 insertions, 14 deletions
diff --git a/README.markdown b/README.markdown index d238332..4067be9 100644 --- a/README.markdown +++ b/README.markdown @@ -10,8 +10,6 @@ NOTE This software is nowhere near complete. To try it out: $ cp hcl_conf.yml.example hcl_conf.yml $ $EDITOR hcl_conf.yml $ ./bin/hcl show [date] - $ ./bin/hcl tasks - $ ./bin/hcl start <task_id> ### Prerequisites @@ -22,16 +20,41 @@ NOTE This software is nowhere near complete. To try it out: ## Usage -NOTE that the only currently implemented commands are show, tasks and start. +NOTE that /add/, /rm/ and /stop/ are not yet implemented. hcl show [date] hcl tasks - hcl start <task_id> [msg] - hcl add <task_id> <duration> [msg] + hcl set <key> <value ...> + hcl unset <key> + hcl start (<task_alias> | <project_id> <task_id>) [msg] + hcl add (<task_alias> | <project_id> <task_id>) <duration> [msg] hcl rm [entry_id] hcl stop [msg] -### Examples +### Starting a Timer + +To start a new timer you need to identify the project and task. After you've +used the show command you can use the tasks command to view a cached list of +available tasks. The first two numbers in each row are the project and task +IDs. You need both values to start a timer: + + $ hcl show + ------------- + 0:00 total + $ hcl tasks + 1234 5678 ClientX Software Development + 1234 9876 ClientX Admin + $ hcl start 1234 5678 adding a new feature + +### Task Aliases + +Since it's not practical to enter two long numbers every time you want to +identify a task, HCl supports task aliases: + + $ hcl set task.xdev 1234 5678 + $ hcl start xdev adding a new feature + +### Date Formats Dates can be expressed in a variety of ways. See the [Chronic documentation][2] for more information about available date input formats. The following @@ -52,6 +75,7 @@ commands show the timesheet for the specified day: - post a time sheet entry - delete a time sheet entry - update a time sheet entry + * better UI for e.g. tasks aliases * command-line configuration * search ~/.hcl_config for configuration * integrate timesheet functionality into aiaio's [harvest gem][3] @@ -14,6 +14,7 @@ require 'hcl/day_entry' class HCl VERSION = "0.1.0" + SETTINGS_FILE = "#{ENV['HOME']}/.hcl_settings" class UnknownCommand < StandardError; end @@ -40,6 +41,7 @@ class HCl def initialize conf_file config = YAML::load File.read(conf_file) TimesheetResource.configure config + read_settings end def process_args *args @@ -64,7 +66,7 @@ Examples: Options: EOM - stop_on %w[ show tasks add rm start stop ] + stop_on %w[ show tasks set unset add rm start stop ] end @command = args.shift @args = args @@ -74,12 +76,48 @@ EOM def tasks Task.all.each do |task| # TODO more information and formatting options - puts "#{task.id}\t#{task}" + puts "#{task.project.id} #{task.id}\t#{task}" end end + def read_settings + settings_file = "#{ENV['HOME']}/.hcl_settings" + if File.exists? settings_file + @settings = YAML.load(File.read(settings_file)) + end + end + + def write_settings + File.open(SETTINGS_FILE, 'w') do |f| + f.write @settings.to_yaml + end + end + + def set key = nil, *args + if key.nil? + @settings.each do |k, v| + puts "#{k}: #{v}" + end + else + value = args.join(' ') + @settings ||= {} + @settings[key] = value + write_settings + end + end + + def unset key + @settings.delete key + write_settings + end + def start *args - task = Task.find args.shift + ident = args.shift + task = if @settings["task.#{ident}"] + Task.find *@settings["task.#{ident}"].split(/\s+/) + else + Task.find ident, args.shift + end puts "Starting timer for #{task}" day_entry = task.start(*args) puts "Time is running on #{day_entry}" @@ -100,7 +138,7 @@ EOM # Convert from decimal to a string of the form HH:MM. def as_hours hours minutes = hours.to_f * 60.0 - "#{(minutes / 60).to_i}:#{(minutes % 60).to_i}" + sprintf "%d:%02d", (minutes / 60).to_i, (minutes % 60).to_i end def not_implemented *args diff --git a/lib/hcl/task.rb b/lib/hcl/task.rb index 0874f51..1a742ce 100644 --- a/lib/hcl/task.rb +++ b/lib/hcl/task.rb @@ -17,8 +17,8 @@ class HCl YAML.load File.read(File.join(ENV['HOME'],'.hcl_tasks')) end - def self.find id - all.detect {|t| t.id == id } + def self.find project_id, id + all.detect {|t| t.project.id == project_id && t.id == id } end def to_s @@ -27,7 +27,7 @@ class HCl def start *args notes = args.join ' ' - day = DayEntry.from_xml Task.post("daily/add", <<-EOT) + days = DayEntry.from_xml Task.post("daily/add", <<-EOT) <request> <notes>#{notes}</notes> <hours></hours> @@ -36,7 +36,7 @@ class HCl <spent_at type="date">#{Date.today}</spent_at> </request> EOT - return day + days.first end end end |
