Class: PT::CLI

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

Constant Summary collapse

TYPE =
%w[feature bug chore release]
ACTION =
%w[show open start finish deliver accept reject done assign estimate tasks comment add_label edit unstart]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IO

#ask, #ask_secret, #choose_action, #choose_filter, #clear, #compact_message, #congrats, #error, #get_open_story_task_from_params, #message, #project_to_s, #prompt, #quit, #select, #select_story_from_paginated_table, #split_lines, #title, #user_s

Methods included from Action

#accept_story, #add_label_story, #assign_story, #choose_person, #comment_story, #copy_story_id, #copy_story_url, #create_interactive_story, #deliver_story, #done_story, #edit_story, #edit_story_task, #edit_using_editor, #estimate_story, #finish_story, #open_story, #open_story_from, #prompt, #reject_story, #save_recent_task, #show_story, #start_story, #tasks_story, #unstart_story

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



29
30
31
32
33
34
# File 'lib/pt/cli.rb', line 29

def initialize(*args)
  super
  @config = PT::Configuration.new
  @client = @config.client || Client.new
  @project = @client.project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



22
23
24
# File 'lib/pt/cli.rb', line 22

def project
  @project
end

Instance Method Details

#create(title = nil) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/pt/cli.rb', line 137

def create(title =nil)
  if title
    owner_id = if options[:owner] && (owner = @client.find_member(options[:owner]))
                 owner.person.id
               else
                 nil
               end
    description = edit_using_editor if options[:m]
    params = {
      name: title,
      requested_by_id: Settings[:user_id],
      owner_ids: [owner_id],
      description: description
    }
    params[:story_type] = options[:type] if options[:type]
    story = @client.create_story(params)
    congrats("Story with title #{story.name} has been created \n #{story.url}")
  else
    create_interactive_story
  end
end

#find(query = nil) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/pt/cli.rb', line 163

def find(query=nil)
  query ||= ask("Please type seach query") { |q| q.readline = true }
  story = select_story_from_paginated_table(title: "Search result for #{query}")do |page|
    @client.get_stories(filter: query, page: page)
  end
  show_story(story)
end

#label(_label = nil) ⇒ Object



72
73
74
75
76
77
# File 'lib/pt/cli.rb', line 72

def label(_label=nil)
  _label ||= select('Please select label', LabelsTable.new(@client.project.labels)).name
  select_story_from_paginated_table(title: "stories with label:#{_label}") do |page|
    @client.get_stories(filter: "label:#{_label}", page: page)
  end
end

#list(owner = nil) ⇒ Object



107
108
109
110
111
112
# File 'lib/pt/cli.rb', line 107

def list(owner = nil)
  owner = choose_person.initials unless owner
  select_story_from_paginated_table(title: "stories for #{owner}") do |page|
    @client.get_stories(filter: "owner:#{owner} -state:accepted", page: page)
  end
end

#myworkObject



91
92
93
94
95
# File 'lib/pt/cli.rb', line 91

def mywork
  select_story_from_paginated_table(title: 'My Work') do |page|
    @client.get_stories(filter: "owner:#{Settings[:user_name]} -state:accepted", page: page)
  end
end

#notificationsObject



172
173
174
# File 'lib/pt/cli.rb', line 172

def notifications
  NotificationsTable.new(@client.notifications).print
end

#recentObject



115
116
117
118
119
120
# File 'lib/pt/cli.rb', line 115

def recent
  title("Your recent stories from #{project_to_s}")
  select_story_from_paginated_table(title: "recent stories") do |page|
    @client.get_stories(filter: Settings[:recent_tasks].join(','), page: page)
  end
end