Class: EPC::Command::ShowProjectCommand

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



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/epc/command/project/show_project_command.rb', line 6

def execute(args = [])
  require_object
  @showable_translations = {
    :config => :config_values,
    :services => :service_versions,
    :versions => :pushed_versions
  }

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

  status, response, message = client.get(EPC::Config::PROJECTS_PATH + "/#{object_id}?include=dependencies,roles,config_values,service_versions,libraries,pushed_versions")
  if status.failure?
    say_err("Request failed: [#{response[:message]}]")
    return status
  end

  response[:created_at] = Time.parse(response[:created_at]).strftime("%m/%d/%Y %I:%M%p")
  response[:last_build_date] = Time.parse(response[:last_build_date]).strftime("%m/%d/%Y %I:%M%p") unless response[:last_build_date].nil? || response[:last_build_date] == "N/A"
  response[:last_push_date] = Time.parse(response[:last_push_date]).strftime("%m/%d/%Y %I:%M%p") unless response[:last_push_date].nil? || response[:last_push_date] == "N/A"
  response[:last_build_status] = nil if response[:last_build_status] == "N/A" # temp hack 
  response[:last_build_status] = (response[:last_build_status] ? "BUILT" : "FAILED" rescue nil) unless response[:last_build_status].nil?
  response[:last_push_by_id] = response[:last_push_by][:id]
  response[:last_push_by_name] = response[:last_push_by][:name]

  response[:pushed_versions].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 ""
    resp[:build_note] = "N/A" if resp[:build_note].blank?
  end


  response[:dependencies] = []
  response[:dependency_definitions].each do |dep_def|
    response[:dependencies] << {
      id:              dep_def[:id],
      parent_id:       dep_def[:parent_id],
      dependency_id:   dep_def[:dependency][:id],
      dependency_name: dep_def[:dependency][:name],
      type:            dep_def[:dependency_kind]
    }
  end

  @response = response

  projects_table = EPC::TabularOutputter.new([response], {:id => "ID", :name => "NAME", :uri_name => "URI NAME", :created_at => "CREATED AT", :last_build_status => "BUILD STATUS", :last_build_date => "BUILD DATE", :last_build_version => "BUILD VERSION"})
  
  last_push_table = EPC::TabularOutputter.new([response], {:last_push_by_id => "USER ID", :last_push_by_name => "USER NAME", :last_push_date => "DATE"})

  dependencies_table = EPC::TabularOutputter.new(response[:dependencies], [:id, :parent_id, :dependency_id, :dependency_name, :type])

  config_values_table = EPC::TabularOutputter.new(response[:config_values], [:id, :name, :no_override, :value, :value_type, :required])

  roles_table = EPC::TabularOutputter.new(response[:roles], [:id, :name])

  services_table = EPC::TabularOutputter.new(response[:service_versions], [:id, :label, :definition_name])

  libraries_table = EPC::TabularOutputter.new(response[:libraries], [:id, :name, :language, :library_version, :group])

  versions_table = EPC::TabularOutputter.new(response[:pushed_versions], {:id => "VERSION", :user_name => "USER", :built => "BUILD STATUS", :build_date => "BUILD DATE", :push_note => "PUSH NOTE", :build_note => "BUILD NOTE"})

  if @showables.blank?
    say("\nProject details:")
    say(projects_table.print)
    
    say("\nLast push info:")
    say(last_push_table.print)
  end

  if show? :dependencies
    say("\nDependencies:")
    say(dependencies_table.print)
  end

  if show? :config
    say("\nConfig values:")
    say(config_values_table.print)
  end

  if show? :roles
    say("\nRoles:")
    say(roles_table.print)
  end

  if show? :services
    say("\nServices:")
    say(services_table.print)
  end

  if show? :libraries
    say("\nLibraries:")
    say(libraries_table.print)
  end

  if show? :versions
    say("\nVersions")
    say(versions_table.print)
  end

  return status
end