Class: PT::CLI

Inherits:
Thor
  • Object
show all
Includes:
Action, Helper
Defined in:
lib/pt/cli.rb

Constant Summary

Constants included from Helper

Helper::GLOBAL_CONFIG_PATH, Helper::LOCAL_CONFIG_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#ask, #ask_secret, #check_local_config_path, #compact_message, #congrats, #edit_story_task, #error, #find_owner, #find_task, #get_local_config_path, #get_open_story_task_from_params, #load_global_config, #load_local_config, #message, #print_stories_table, #project_to_s, #quit, #save_config, #save_recent_task, #select, #select_story_from_paginated_table, #show_activity, #split_lines, #task_by_id_or_pt_id, #task_type_or_nil, #title, #user_s

Methods included from Action

#accept_story, #assign_story, #comment_story, #deliver_story, #done_story, #estimate_story, #finish_story, #label_story, #open_story, #reject_story, #show_story, #start_story, #tasks_story

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



16
17
18
19
20
21
22
23
# File 'lib/pt/cli.rb', line 16

def initialize(*args)
  super
  @io = HighLine.new
  @global_config = load_global_config
  @local_config = load_local_config
  @client = Client.new(@global_config[:api_number], @local_config)
  @project = @client.project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



11
12
13
# File 'lib/pt/cli.rb', line 11

def project
  @project
end

Instance Method Details

#create(title = nil) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/pt/cli.rb', line 105

def create(title =nil)
  owner = options[:owner]
  type = options[:type]
  requester_id = @local_config[:user_id]
  if title
    name = title
    owner = owner || @local_config[:user_name]
    type = task_type_or_nil(owner) || task_type_or_nil(type) || 'feature'
  else
    title("Let's create a new task:")
    name = ask("Name for the new task:")
  end

  owner = @client.find_member(owner).person.id if owner.kind_of?(String)

  unless owner
    if ask('Do you want to assign it now? (y/n)').downcase == 'y'
      members = @client.get_members
      table = PersonsTable.new(members.map(&:person))
      owner = select("Please select a member to assign him the task.", table).id
    else
      owner = nil
    end
    type = ask('Type? (c)hore, (b)ug, anything else for feature)')
  end

  type = case type
         when 'c', 'chore'
           'chore'
         when 'b', 'bug'
           'bug'
         else
           'feature'
         end

  owner_ids = [owner]
  # did you do a -m so you can add a description?
  if options[:m]
    editor = ENV.fetch('EDITOR') { 'vi' }
    temp_path = "/tmp/editor-#{ Process.pid }.txt"
    system "#{ editor } #{ temp_path }"

    description = File.read(temp_path)
  end

  story = @client.create_story(
    name: name,
    owner_ids: owner_ids,
    requested_by_id: requester_id,
    story_type: type,
    description: description
  )
  congrats("#{type} for #{owner} open #{story.url}")
  show_story(story)
end

#find(query) ⇒ Object



162
163
164
165
# File 'lib/pt/cli.rb', line 162

def find(query)
  stories = @client.get_stories(filter: query, page: options[:page])
  print_stories_table(stories)
end

#list(owner = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/pt/cli.rb', line 66

def list(owner = nil)
  if owner
    if owner == "all"
      stories = @client.get_work
    else
      stories = @client.get_my_work(owner)
    end
  else
    members = @client.get_members
    table = MembersTable.new(members)
    user = select("Please select a member to see his tasks.", table).name
    title("Work for #{user} in #{project_to_s}")
    stories = @client.get_my_work(user)
  end
  print_stories_table(stories)
end

#myworkObject



60
61
62
63
# File 'lib/pt/cli.rb', line 60

def mywork
  stories = @client.get_stories(filter: "owner:#{@local_config[:user_name]} -state:accepted", page: options[:page])
  print_stories_table(stories)
end

#recentObject



84
85
86
87
88
# File 'lib/pt/cli.rb', line 84

def recent
  title("Your recent stories from #{project_to_s}")
  stories = @project.stories( ids: @local_config[:recent_tasks].join(',') )
  MultiUserTasksTable.new(stories).print @global_config
end

#updatesObject



168
169
170
171
172
173
174
175
# File 'lib/pt/cli.rb', line 168

def updates
  activities = @client.get_activities
  tasks = @client.get_my_work
  title("Recent Activity on #{project_to_s}")
  activities.each do |activity|
    show_activity(activity, tasks)
  end
end