Method: Sfn::Command::Events#execute!

Defined in:
lib/sfn/command/events.rb

#execute!Object

Run the events list action



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
# File 'lib/sfn/command/events.rb', line 13

def execute!
  name_required!
  name = name_args.first
  ui.info "Events for Stack: #{ui.color(name, :bold)}\n"
  @seen_events = []
  @stack = provider.stack(name)
  if stack
    api_action!(:api_stack => stack) do
      table = ui.table(self) do
        table(:border => false) do
          events = get_events
          row(:header => true) do
            allowed_attributes.each do |attr|
              width_val = events.map { |e| e[attr].to_s.length }.push(attr.length).max + 2
              width_val = width_val > 70 ? 70 : width_val < 20 ? 20 : width_val
              column attr.split("_").map(&:capitalize).join(" "), :width => width_val
            end
          end
          events.each do |event|
            row do
              allowed_attributes.each do |attr|
                column event[attr]
              end
            end
          end
        end
      end.display
      if config[:poll]
        while (stack.reload.in_progress?)
          to_wait = config.fetch(:poll_wait_time, 10).to_f
          while (to_wait > 0)
            sleep(0.1)
            to_wait -= 0.1
          end
          stack.resources.reload
          table.display
        end
      end
    end
  else
    ui.fatal "Failed to locate requested stack: #{ui.color(name, :bold, :red)}"
    raise "Failed to locate stack: #{name}!"
  end
end