Sha256: ca44f2e3f118e5fdb83c4ee811b93e2f6863cdad51722fe5dd5215bf2fe9881c

Contents?: true

Size: 1.42 KB

Versions: 12

Compression:

Stored size: 1.42 KB

Contents

require "aws-sdk-cloudformation"
require "swa/cli/base_command"
require "swa/cli/collection_behaviour"
require "swa/cli/item_behaviour"
require "swa/cloud_formation/stack"

module Swa
  module CLI

    class CloudFormationCommand < BaseCommand

      subcommand ["stack", "s"], "Show stack" do

        parameter "NAME", "stack name"

        include ItemBehaviour

        subcommand "template", "Show template" do

          def execute
            display_data(stack.template_data)
          end

        end

        %w(parameters outputs resources).each do |thing|
          class_eval <<-RUBY
            subcommand "#{thing}", "Show #{thing}" do
              def execute
                display_data(stack.#{thing})
              end
            end
          RUBY
        end

        private

        def stack
          Swa::CloudFormation::Stack.new(cloud_formation.stack(name))
        end

        alias_method :item, :stack

      end

      subcommand ["stacks"], "Show stacks" do

        include CollectionBehaviour

        private

        def collection
          query_for(:stacks, Swa::CloudFormation::Stack)
        end

      end

      protected

      def cloud_formation
        ::Aws::CloudFormation::Resource.new(aws_config)
      end

      def query_for(query_method, model)
        aws_resources = cloud_formation.public_send(query_method, query_options)
        model.list(aws_resources)
      end

    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
swa-0.8.3 lib/swa/cli/cloud_formation_command.rb
swa-0.8.2 lib/swa/cli/cloud_formation_command.rb
swa-0.8.1 lib/swa/cli/cloud_formation_command.rb
swa-0.8.0 lib/swa/cli/cloud_formation_command.rb
swa-0.7.7 lib/swa/cli/cloud_formation_command.rb
swa-0.7.6 lib/swa/cli/cloud_formation_command.rb
swa-0.7.5 lib/swa/cli/cloud_formation_command.rb
swa-0.7.4 lib/swa/cli/cloud_formation_command.rb
swa-0.7.3 lib/swa/cli/cloud_formation_command.rb
swa-0.7.2 lib/swa/cli/cloud_formation_command.rb
swa-0.7.1 lib/swa/cli/cloud_formation_command.rb
swa-0.7.0 lib/swa/cli/cloud_formation_command.rb