Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,25 +1,45 @@ | |||
require "optparse" | require "optparse" | ||
require "chronic_duration" | |||
|
|
||
module TogglCmd | module TogglCmd | ||
|
|
||
NAME = "toggl-gem" | NAME = "toggl-gem" | ||
PROJECT_FIELDS = %w(client name) | |||
TASK_FIELDS = %w(project description start duration billable) | |||
|
|
||
class Runner | class Runner | ||
|
|
||
def self.toggl(args) | def self.toggl(args) | ||
token = IO.readlines(File.expand_path("~/.toggl")).join.strip | token = IO.readlines(File.expand_path("~/.toggl")).join.strip | ||
options = RunnerOptions.new(args) | options = RunnerOptions.new(args) | ||
if options[:tasks] | if options[:tasks] | ||
puts Toggl.new(token, NAME).tasks | prettify_tasks(Toggl.new(token, NAME).tasks) | ||
elsif options[:projects] | elsif options[:projects] | ||
puts Toggl.new(token, NAME).projects | prettify_projects(Toggl.new(token, NAME).projects) | ||
elsif options.any? | 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 | else | ||
puts options.opts | puts options.opts | ||
end | end | ||
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 | ||
|
|||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters