summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorZack Hobson2013-11-21 12:02:47 -0800
committerZack Hobson2013-11-21 12:06:52 -0800
commit125133158e4d021526638789848b238ecd268f49 (patch)
tree404e2c6db5e8f85d09943e22ed3f2fd7908faf5b /lib
parent86ff02c8380fc50cfa7e0d4e6d0cfd7be56fb633 (diff)
downloadhcl-125133158e4d021526638789848b238ecd268f49.tar.bz2
Test and dev improvements
* removed dependency on shoulda * added bundler support for dev/testing * test coverage reporting * added some command tests
Diffstat (limited to 'lib')
-rw-r--r--lib/hcl/app.rb15
-rw-r--r--lib/hcl/commands.rb18
2 files changed, 20 insertions, 13 deletions
diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb
index 684f521..c86e3c5 100644
--- a/lib/hcl/app.rb
+++ b/lib/hcl/app.rb
@@ -9,20 +9,23 @@ module HCl
include HCl::Utility
include HCl::Commands
- SETTINGS_FILE = "#{ENV['HOME']}/.hcl/settings.yml"
- CONFIG_FILE = "#{ENV['HOME']}/.hcl/config.yml"
+
+ HCL_DIR = ENV['HCL_DIR'] || "#{ENV['HOME']}/.hcl"
+ SETTINGS_FILE = "#{HCL_DIR}/settings.yml"
+ CONFIG_FILE = "#{HCL_DIR}/config.yml"
OLD_SETTINGS_FILE = "#{ENV['HOME']}/.hcl_settings"
OLD_CONFIG_FILE = "#{ENV['HOME']}/.hcl_config"
- def initialize
+ def configure
FileUtils.mkdir_p(File.join(ENV['HOME'], ".hcl"))
read_config
read_settings
+ self
end
# Run the given command and arguments.
def self.command *args
- hcl = new.process_args(*args).run
+ new.configure.process_args(*args).run
end
# Return true if the string is a known command, false otherwise.
@@ -47,10 +50,10 @@ module HCl
end
end
else
- start @command, *@args
+ puts start(@command, *@args)
end
else
- show
+ puts show
end
rescue RuntimeError => e
STDERR.puts "Error: #{e}"
diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb
index 3d1b494..c245710 100644
--- a/lib/hcl/commands.rb
+++ b/lib/hcl/commands.rb
@@ -5,7 +5,10 @@ module HCl
module Commands
def tasks project_code=nil
tasks = Task.all
- DayEntry.all if tasks.empty? # cache tasks
+ if tasks.empty? # cache tasks
+ DayEntry.all
+ tasks = Task.all
+ end
tasks.select! {|t| t.project.code == project_code } if project_code
if tasks.empty?
puts "No matching tasks."
@@ -52,14 +55,14 @@ module HCl
def unalias task
unset "task.#{task}"
- puts "Removed task alias @#{task}."
+ "Removed task alias @#{task}."
end
def alias task_name, *value
task = Task.find *value
if task
set "task.#{task_name}", *value
- puts "Added alias @#{task_name} for #{task}."
+ "Added alias @#{task_name} for #{task}."
else
puts "Unrecognized project and task ID: #{value.inspect}"
exit 1
@@ -84,7 +87,7 @@ module HCl
timer = task.start \
:starting_time => starting_time,
:note => args.join(' ')
- puts "Started timer for #{timer} (at #{current_time})"
+ "Started timer for #{timer} (at #{current_time})"
end
def log *args
@@ -119,14 +122,15 @@ module HCl
def show *args
date = args.empty? ? nil : Chronic.parse(args.join(' '))
total_hours = 0.0
+ result = ''
DayEntry.all(date).each do |day|
running = day.running? ? '(running) ' : ''
columns = HighLine::SystemExtensions.terminal_size[0]
- puts "\t#{day.formatted_hours}\t#{running}#{day.project}: #{day.notes.lines.last}"[0..columns-1]
+ result << "\t#{day.formatted_hours}\t#{running}#{day.project}: #{day.notes.lines.last}\n"[0..columns-1]
total_hours = total_hours + day.hours.to_f
end
- puts "\t" + '-' * 13
- puts "\t#{as_hours total_hours}\ttotal (as of #{current_time})"
+ result << ("\t" + '-' * 13) << "\n"
+ result << "\t#{as_hours total_hours}\ttotal (as of #{current_time})\n"
end
def resume *args