Sha256: 597ac2e90fb2275fcc6c184a63714170d28d3c3dfbe501529d0b4d447c231c80

Contents?: true

Size: 1.63 KB

Versions: 22

Compression:

Stored size: 1.63 KB

Contents

require 'sfn'

module Sfn
  class Command
    # List command
    class List < Command

      include Sfn::CommandModule::Base

      # Run the list command
      def execute!
        ui.table(self) do
          table(:border => false) do
            stacks = api_action!{ get_stacks }
            row(:header => true) do

              allowed_attributes.each do |attr|
                width_val = stacks.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
            get_stacks.each do |stack|
              row do
                allowed_attributes.each do |attr|
                  column stack[attr]
                end
              end
            end
          end
        end.display
      end

      # Get the list of stacks to display
      #
      # @return [Array<Hash>]
      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

      # @return [Array<String>] default attributes to display
      def default_attributes
        if(provider.connection.provider == :aws)
          %w(name created updated status template_description)
        else
          %w(name created updated status description)
        end
      end

    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sfn-3.0.28 lib/sfn/command/list.rb
sfn-3.0.26 lib/sfn/command/list.rb
sfn-3.0.24 lib/sfn/command/list.rb
sfn-3.0.22 lib/sfn/command/list.rb
sfn-3.0.20 lib/sfn/command/list.rb
sfn-3.0.18 lib/sfn/command/list.rb
sfn-3.0.16 lib/sfn/command/list.rb
sfn-3.0.14 lib/sfn/command/list.rb
sfn-3.0.12 lib/sfn/command/list.rb
sfn-3.0.10 lib/sfn/command/list.rb
sfn-3.0.8 lib/sfn/command/list.rb
sfn-3.0.6 lib/sfn/command/list.rb
sfn-3.0.4 lib/sfn/command/list.rb
sfn-3.0.2 lib/sfn/command/list.rb
sfn-3.0.0 lib/sfn/command/list.rb
sfn-2.2.0 lib/sfn/command/list.rb
sfn-2.1.12 lib/sfn/command/list.rb
sfn-2.1.10 lib/sfn/command/list.rb
sfn-2.1.8 lib/sfn/command/list.rb
sfn-2.1.6 lib/sfn/command/list.rb