Sha256: 369efba5bffea5419b5af95b71ca2353acb85d89c85e72fe9228118a6bce1b3b

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require 'thor'
require_relative '../pulumi'
require_relative '../logger'

module Bauble
  module Cli
    module Commands
      # Up command
      module Destroy
        class << self
          def included(thor)
            thor.class_eval do
              desc 'destroy', 'Destroy the application'
              method_option :stack, type: :string, desc: 'The stack to destroy', aliases: '-s'

              def destroy
                Logger.logo
                Logger.nl

                setup_app

                # check for any stacks
                raise 'No stacks found' if @app.stacks.empty?

                # check for multiple stacks
                if @app.stacks.length > 1 && options[:stack].nil?
                  Logger.error 'Must provide a stack when multiple are defined'
                  exit(1)
                end

                unless yes?('Are you sure you want to destroy the application? [y/N]')
                  Logger.log('Destroy aborted')
                  exit(0)
                end

                Logger.block_log('Destroying application...')

                # set up stack
                stack_name = options[:stack] || @app.stacks.first.name
                @app.change_current_stack(stack_name)

                # initialize pulumi
                pulumi.init!

                # create or select stack
                pulumi.create_or_select_stack(stack_name)

                # destroy the stack
                pulumi.destroy
                Logger.log "Destroy complete\n"
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bauble_core-0.5.3 lib/bauble/cli/commands/destroy.rb
bauble_core-0.5.2 lib/bauble/cli/commands/destroy.rb
bauble_core-0.5.1 lib/bauble/cli/commands/destroy.rb