Class: EPC::Command::ListDeploymentsCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/deployment/list_deployments_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, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

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(args = []) ⇒ Object

Raises:



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
37
38
39
40
41
42
43
44
# File 'lib/epc/command/deployment/list_deployments_command.rb', line 5

def execute(args = [])
  path = File.expand_path(".")

  if target_type.present?
    id = retrieve_identifier_for(target_type, target_id)
    if target_type.downcase == "solution"
      url = EPC::Config::SOLUTIONS_PATH + "/#{id}/deployments"
    elsif target_type.downcase == "deploymentstage"
      url = EPC::Config::DEPLOYMENT_STAGES_PATH + "/#{id}/deployments"
    elsif target_type.downcase == "user"
      url = EPC::Config::USERS_PATH + "/#{id}/deployments"
    end
  elsif EPC::Config.is_solution_dir?(path) || EPC::Config.is_project_dir?(path)
    id, name = infer_solution_context(nil, path)
    if id.present?
      url = EPC::Config::SOLUTIONS_PATH + "/#{id}/deployments"
    end
  end

  raise FatalError, "Solution/stage/deployer could not be inferred." if id.nil?

  status, response, headers = client.get(url)

  if status.failure?
    say_err("Deployments retrieval failed with [#{response[:message]}]")
  elsif response.empty?
    say("You have no deployments created. You can create them with epc create deployment.")
  else
    response = response.select{|d| d[:status] == @options[:status]} unless @options[:status].nil? 
    if response.empty?
      say("You have no deployments created. You can create them with epc create deployment.")
      return 0
    end
    response.sort!{|a, b| b[:id] <=> a[:id]}
    deployments_table = EPC::TabularOutputter.new(response, {:id => "ID", :deployer_name => "DEPLOYER", :solution_name => "SOLUTION", :deployment_stage_name => "STAGE", :status => "STATUS"})
    say(deployments_table.print)
  end
  return status

end