Permalink
Browse files

use Hirb to prettify console output

  • Loading branch information...
atog committed Mar 16, 2010
1 parent 37ab4b5 commit 10ad5e9676946b3e2a110f8bb76ced84e0a86983
Showing with 34 additions and 7 deletions.
  1. +1 −0 Rakefile
  2. +3 −0 bin/toggl
  3. +25 −5 lib/toggl_cmd/runner.rb
  4. +5 −2 toggl.gemspec
View
@@ -14,6 +14,7 @@ begin
gem.test_files = []
gem.add_dependency('httparty', '>= 0.5.2')
gem.add_dependency('chronic_duration', '>= 0.9.0')
+ gem.add_dependency('hirb', '>= 0.3.1')
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
View
@@ -6,5 +6,8 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'toggl'
require 'toggl_cmd/runner'
require 'toggl_cmd/runner_options'
+require 'hirb'
+require 'hirb/import_object'
+Hirb.enable
TogglCmd::Runner.toggl(ARGV)
View
@@ -1,25 +1,45 @@
require "optparse"
+require "chronic_duration"
module TogglCmd
NAME = "toggl-gem"
+ PROJECT_FIELDS = %w(client name)
+ TASK_FIELDS = %w(project description start duration billable)
class Runner
def self.toggl(args)
token = IO.readlines(File.expand_path("~/.toggl")).join.strip
options = RunnerOptions.new(args)
if options[:tasks]
- puts Toggl.new(token, NAME).tasks
+ prettify_tasks(Toggl.new(token, NAME).tasks)
elsif options[:projects]
- puts Toggl.new(token, NAME).projects
+ prettify_projects(Toggl.new(token, NAME).projects)
elsif options.any?
- Toggl.new(token, NAME, options.delete(:debug)).create_task(options)
+ prettify_tasks(Toggl.new(token, NAME, options.delete(:debug)).create_task(options))
else
puts options.opts
end
end
-
+
+ private
+
+ def self.prettify_tasks(values)
+ values = [values] unless values.is_a?(Array)
+ values.each do |value|
+ value["project"] = value["project"]["name"]
+ value["workspace"] = value["workspace"]["name"]
+ value["duration"] = ChronicDuration.output(value["duration"].to_i, :format => :short)
+ value["start"] = DateTime.parse(value["start"]).strftime("%d/%m/%Y")
+ end
+ values.view(:class => :table, :fields => TASK_FIELDS)
+ end
+
+ def self.prettify_projects(values)
+ values.view(:class => :table, :fields => PROJECT_FIELDS)
+ end
+
end
-
+
end
View
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{toggl}
- s.version = "0.1.1"
+ s.version = "0.2.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Koen Van der Auwera"]
- s.date = %q{2010-03-14}
+ s.date = %q{2010-03-16}
s.default_executable = %q{toggl}
s.description = %q{Toggl provides a simple REST-style JSON API over standard HTTP - http://www.toggl.com}
s.email = %q{koen@atog.be}
@@ -36,13 +36,16 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
s.add_runtime_dependency(%q<chronic_duration>, [">= 0.9.0"])
+ s.add_runtime_dependency(%q<hirb>, [">= 0.3.1"])
else
s.add_dependency(%q<httparty>, [">= 0.5.2"])
s.add_dependency(%q<chronic_duration>, [">= 0.9.0"])
+ s.add_dependency(%q<hirb>, [">= 0.3.1"])
end
else
s.add_dependency(%q<httparty>, [">= 0.5.2"])
s.add_dependency(%q<chronic_duration>, [">= 0.9.0"])
+ s.add_dependency(%q<hirb>, [">= 0.3.1"])
end
end

0 comments on commit 10ad5e9

Please sign in to comment.