Sha256: 119b531cba2ab52f6b34ac2a36f3a7fe17757fec7a661d69c6b434d0464e46f0

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

module Humidifier
  module Reservoir
    # A CLI for running commands to manipulate the stacks that Reservoir knows
    # about.
    class CLI < Thor
      class_option :aws_profile, desc: 'The AWS profile to authenticate with', aliases: ['-p']

      class_option :debug, desc: 'Sets up debug mode', aliases: ['-d']
      class_around :safe_execute

      desc 'deploy [?stack]', 'Update one or all stacks'
      option :wait, desc: 'Wait for the stack to create/update', type: :boolean, default: false
      def deploy(name = nil)
        stack_names = name ? [name] : Reservoir.stacks
        authorize

        stack_names.each do |stack_name|
          stack = Stack.new(stack_name)
          puts "Deploying #{stack.stack_name}"
          stack.deploy(options[:wait])
        end
      end

      desc 'display [stack] [?pattern]', 'Display the CloudFormation JSON for a given stack'
      def display(name, pattern = nil)
        puts Stack.new(name, pattern && /#{pattern}/i).to_cf
      end

      desc 'validate [?stack]', 'Validate that one or all stacks are valid with CloudFormation'
      def validate(name = nil)
        stack_names = name ? [name] : Reservoir.stacks
        authorize

        print 'Validating... '
        puts 'Valid.' if stack_names.all? { |stack_name| Stack.new(stack_name).valid? }
      end

      no_commands do
        def authorize
          return unless options[:aws_profile]
          Aws.config[:credentials] = Aws::SharedCredentials.new(profile_name: options[:aws_profile])
        end

        def safe_execute
          yield
        rescue Error => error
          raise error if options[:debug]
          puts error.message
          exit 1
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
humidifier-reservoir-0.1.0 lib/humidifier/reservoir/cli.rb
humidifier-reservoir-0.0.1 lib/humidifier/reservoir/cli.rb