Method: Cf::Badge#list

Defined in:
lib/cf/cli/badge.rb

#list(name = nil) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/cf/cli/badge.rb', line 213

def list(name = nil)
  #set badge basic credentials
  line_source = Dir.pwd
  yaml_source = "#{line_source}/line.yml"
  set_target_uri(false)
  set_api_key(yaml_source)
  set_target_uri(false)
  CF. = CF::Account.info['name']

  #list all badges if name is not present else list the specific badge
  if name
    badge_resp = CF::Badge.list(name)
  else
    badge_resp = CF::Badge.list
  end

  #show list of badges in the tabular view
  if badges = badge_resp["badges"]
    say "Listing badges within your account" , :green
    badges.sort! { |a, b| a['name'] <=> b['name'] }
    badge_table = table do |t|
      t.headings = ["Name", 'Number Of Tasks', 'Lines Associated', 'Workers', 'Description']
      badges.each do |badge|
        badge = Hashie::Mash.new(badge)
        t << [badge.name, badge.num_of_tasks, badge.lines_associated, badge.workers, badge.description]
      end
    end
    say(badge_table)
  else
    say badge_resp["error"]["message"], :red
  end
end