diff options
Diffstat (limited to 'lib/hcl.rb')
| -rw-r--r-- | lib/hcl.rb | 46 |
1 files changed, 42 insertions, 4 deletions
@@ -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 |
