Module: Asana::CLI
- Defined in:
- lib/asana-cli.rb,
lib/asana-cli/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
- .close(task_id) ⇒ Object
- .comment(task_id, message) ⇒ Object
- .list_workspaces ⇒ Object
- .project_tasks(project_id, workspace_id = nil) ⇒ Object
- .resolve(w, p, t) ⇒ Object
- .show_task(task_id, project_id = nil, workspace_id = nil) ⇒ Object
- .workspace_tasks(workspace_id) ⇒ Object
Class Method Details
.close(task_id) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/asana-cli.rb', line 9 def close(task_id) task = Asana::Task.find(task_id) task.create_story :text => opts[:message] if opts[:message] task.modify(:completed => true) puts "Task %s closed!".light_green % task_id end |
.comment(task_id, message) ⇒ Object
16 17 18 19 |
# File 'lib/asana-cli.rb', line 16 def comment(task_id, ) task = Asana::Task.find(task_id) task.create_story :text => end |
.list_workspaces ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/asana-cli.rb', line 51 def list_workspaces puts "\n" puts "Workspaces".light_green puts ("-" * 60).light_white Asana::Workspace.all.each do |workspace| puts "%s\t%s" % [workspace.id.to_s.light_yellow, workspace.name.light_white] end end |
.project_tasks(project_id, workspace_id = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/asana-cli.rb', line 21 def project_tasks(project_id, workspace_id = nil) projects = resolve workspace_id, project_id, nil raise CLIError.new "Unable to find a project named #{project_id}" if projects.empty? projects.each do |project| puts "\n" puts "%s\t Tasks" % project.name.light_green puts ("-" * 60).light_white project.tasks.each do |task| puts "%s\t%s" % [task.id.to_s.light_yellow, task.name.light_white] end puts "\n" end end |
.resolve(w, p, t) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/asana-cli.rb', line 80 def resolve(w, p, t) w_id = w.to_i if w and w.match(/^\d+$/) p_id = p.to_i if p and p.match(/^\d+$/) t_id = t.to_i if t and t.match(/^\d+$/) if t if t_id return [Asana::Task.find(t_id)] elsif p_id Asana::Project.find(p_id).tasks.select {|_t| _t.name.downcase[t.downcase] } else if w_id projects = Asana::Workspace.find(w_id).projects else projects = Asana::Workspace.all.flat_map &:projects end projects = projects.select {|_p| _p.name.downcase[p.downcase] } if p return projects.flat_map do |project| puts project.name project.tasks.select {|_t| _t.name.downcase[t.downcase] } end end elsif p if p_id return [Asana::Project.find(p_id)] else if w_id projects = Asana::Workspace.find(w_id).projects else projects = Asana::Workspace.all.flat_map &:projects end return projects.select {|_p| _p.name.downcase[p.downcase] } end elsif w if w_id return [Asana::Workspace.find(w_id)] else Asana::Workspace.all.select {|_w| _w.name.downcase[w.downcase] } end end end |
.show_task(task_id, project_id = nil, workspace_id = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/asana-cli.rb', line 60 def show_task(task_id, project_id = nil, workspace_id = nil) tasks = resolve workspace_id, project_id, task_id tasks.each do |task| puts task.name.light_green puts "-" * 60 task.attributes.each do |key, val| vals = val if val.is_a? Array vals = val.map {|v| v.respond_to?(:name) ? v.name : v.inspect } elsif val.is_a? Asana::Workspace or val.is_a? Asana::Task::Assignee vals = val.name end vals = vals.join(", ") if vals.is_a? Array puts "%20s\t%s" % [key, vals.to_s.light_white] end puts "\n" end end |
.workspace_tasks(workspace_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/asana-cli.rb', line 36 def workspace_tasks(workspace_id) workspaces = resolve workspace_id, nil, nil raise CLIError.new "Unable to find a workspace named #{workspace_id}" if workspaces.empty? workspaces.each do |workspace| puts "\n" puts "%s\tProjects" % workspace.name.light_green puts ("-" * 60).light_white workspace.projects.each do |project| puts "%s\t%s" % [project.id.to_s.light_yellow, project.name.light_white] end puts "\n" end end |