Class: EPC::Command::ListVersionsCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/list_versions_command.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#go, inherited, #initialize, required_options

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#execute(project = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/epc/command/list_versions_command.rb', line 5

def execute(project = nil)
  solution = @options[:solution_name]
  path = File.expand_path(".")


  solution_id, solution_name = infer_solution_context(solution, path, :get_solution_name => true)
  project_id, project_name = infer_project_context(project, path, solution_id, {:get_project_name => true})

  if project_id.nil?
    say("Project could not be inferred")
    say(EPC::Help::COMMAND_USAGES[:list_versions])
    return 1
  end

  status, response, headers = client.get(EPC::Config::PROJECTS_PATH + "/#{project_id}/versions")

  if status.failure?
    say("Request failed: [#{response[:message]}]")
  elsif response.empty?
    say("There are no project versions available")
  else
    response.each do |resp|
      resp[:build_date] = Time.parse(resp[:build_date]).strftime("%m/%d/%Y %I:%M%p") rescue "N/A"
      resp[:created_at] = Time.parse(resp[:created_at]).strftime("%m/%d/%Y %I:%M%p") rescue "N/A"
      resp[:built] = resp[:built] == 't' ? "BUILT" : "" rescue ""
    end
    versions_table = EPC::TabularOutputter.new(response, {:id => "VERSION", :event => "EVENT", :whodunnit => "USER", :created_at => "DATE", :built => "BUILD STATUS", :build_date => "BUILD DATE"})
    say(versions_table.print)
  end
  return status

end