Class: EPC::Command::ShowSolutionCommand

Inherits:
ShowCommand show all
Defined in:
lib/epc/command/solution/show_solution_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



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
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/epc/command/solution/show_solution_command.rb', line 5

def execute(args = [])
  require_object

  path = File.expand_path(".")

  status, response, message = client.get(EPC::Config::SOLUTIONS_PATH + "/#{object_id}?include=config_values,projects,deployments,deployment_configs")
  if status.failure?
    say_err("Request failed: [#{response[:message]}]")
    return status
  end

  @showables = args[1..-1].map(&:to_sym) rescue []

  response[:build_date] = Time.parse(response[:build_date]).strftime("%m/%d/%Y %I:%M%p") rescue nil
  response[:updated_at] = Time.parse(response[:updated_at]).strftime("%m/%d/%Y %I:%M%p") rescue nil
  solution_table = EPC::TabularOutputter.new([response], [:id, :name, :updated_at, :build_date, :build_status])
  response[:projects].each do |project|
    unless project[:last_build_status].nil?
      project[:last_build_status] = nil if project[:last_build_status] == "N/A" # temp hack 
      project[:last_build_status] = (project[:last_build_status] ? "BUILT" : "FAILED" rescue nil) unless project[:last_build_status].nil?
    end
  end if response[:projects].present?
  projects_table = EPC::TabularOutputter.new(response[:projects], {:id => "ID", :name => "NAME", :current_version_number => "VERSION", :last_build_status => "BUILD_STATUS", :last_build_errors => "ERRORS"})

  response[:deployments].each do |dep|
    dep[:updated_at] = Time.parse(dep[:updated_at]).strftime("%m/%d/%Y %I:%M%p")
    dep[:deployment_stage_name] = dep[:deployment_stage][:name] unless dep[:deployment_stage].nil?
  end if response[:deployments].present?
  deployments_table = EPC::TabularOutputter.new(response[:deployments], {:id => "ID", :deployment_stage_name => "STAGE", :status => "STATUS", :updated_at => "LAST UPDATE"})
  config_values_table = EPC::TabularOutputter.new(response[:config_values], [:name, :value, :require, :value_type])

  @response = response

  if @showables.blank?
    say("\nSolution details:")
    say(solution_table.print)
  end

  if show? :projects
    say("\nProjects:")
    say(projects_table.print)
  end

  if show? :deployments
    say("\nDeployments:")
    say(deployments_table.print)
  end

  return status

end