Class: Sfn::Command::List

Inherits:
Sfn::Command show all
Includes:
Sfn::CommandModule::Base
Defined in:
lib/sfn/command/list.rb

Overview

List command

Instance Method Summary collapse

Methods included from Sfn::CommandModule::Base

included

Methods inherited from Sfn::Command

#config, #initialize

Constructor Details

This class inherits a constructor from Sfn::Command

Instance Method Details

#default_attributesArray<String>

Returns default attributes to display.

Returns:

  • (Array<String>)

    default attributes to display



49
50
51
52
53
54
55
# File 'lib/sfn/command/list.rb', line 49

def default_attributes
  if(provider.connection.provider == :aws)
    %w(name created status template_description)
  else
    %w(name created status description)
  end
end

#execute!Object

Run the list command



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sfn/command/list.rb', line 11

def execute!
  ui.table(self) do
    table(:border => false) do
      stacks = get_stacks
      row(:header => true) do
        allowed_attributes.each do |attr|
          column attr.split('_').map(&:capitalize).join(' '), :width => (stacks.map{|s| s[attr].to_s.length}.max || 20) + 2
        end
      end
      get_stacks.each do |stack|
        row do
          allowed_attributes.each do |attr|
            column stack[attr]
          end
        end
      end
    end
  end.display
end

#get_stacksArray<Hash>

Get the list of stacks to display

Returns:

  • (Array<Hash>)


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sfn/command/list.rb', line 34

def get_stacks
  provider.stacks.all.map do |stack|
    Smash.new(stack.attributes)
  end.sort do |x, y|
    if(y[:created].to_s.empty?)
      -1
    elsif(x[:created].to_s.empty?)
      1
    else
      Time.parse(x[:created].to_s) <=> Time.parse(y[:created].to_s)
    end
  end
end