Sha256: 0f1926b1781ea0bdcb8bace5544fc89320e4c6ad3b5588d8b51b587786ea8c9f

Contents?: true

Size: 1.99 KB

Versions: 19

Compression:

Stored size: 1.99 KB

Contents

require 'optparse'

module Vagrant
  module Command
    class Destroy < Base
      def execute
        options = {}

        opts = OptionParser.new do |opts|
          opts.banner = "Usage: vagrant destroy [vm-name]"
          opts.separator ""

          opts.on("-f", "--force", "Destroy without confirmation.") do |f|
            options[:force] = f
          end
        end

        # Parse the options
        argv = parse_options(opts)
        return if !argv

        @logger.debug("'Destroy' each target VM...")
        with_target_vms(argv, :reverse => true) do |vm|
          if vm.created?
            # Boolean whether we should actually go through with the destroy
            # or not. This is true only if the "--force" flag is set or if the
            # user confirms it.
            do_destroy = false

            if options[:force]
              do_destroy = true
            else
              choice = nil
              begin
                choice = @env.ui.ask(I18n.t("vagrant.commands.destroy.confirmation",
                                            :name => vm.name))
              rescue Errors::UIExpectsTTY
                # We raise a more specific error but one which basically
                # means the same thing.
                raise Errors::DestroyRequiresForce
              end
              do_destroy = choice.upcase == "Y"
            end

            if do_destroy
              @logger.info("Destroying: #{vm.name}")
              vm.destroy
            else
              @logger.info("Not destroying #{vm.name} since confirmation was declined.")
              @env.ui.success(I18n.t("vagrant.commands.destroy.will_not_destroy",
                                     :name => vm.name), :prefix => false)
            end
          else
            @logger.info("Not destroying #{vm.name}, since it isn't created.")
            vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
          end
        end

        # Success, exit status 0
        0
       end
    end
  end
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
bmhatfield-vagrant-1.0.10 lib/vagrant/command/destroy.rb
bmhatfield-vagrant-1.0.9 lib/vagrant/command/destroy.rb
bmhatfield-vagrant-1.0.8 lib/vagrant/command/destroy.rb
bmhatfield-vagrant-1.0.7 lib/vagrant/command/destroy.rb
vagrantup-1.0.7 lib/vagrant/command/destroy.rb
vagrantup-1.0.6 lib/vagrant/command/destroy.rb
vagrantup-1.0.5 lib/vagrant/command/destroy.rb
vagrantup-1.0.4 lib/vagrant/command/destroy.rb
vagrantup-1.0.3 lib/vagrant/command/destroy.rb
vagrantup-1.0.2 lib/vagrant/command/destroy.rb
vagrant-fixed-ssh-1.0.7 lib/vagrant/command/destroy.rb
vagrant-1.0.7 lib/vagrant/command/destroy.rb
vagrant-1.0.6 lib/vagrant/command/destroy.rb
boxcar-0.10005.1 lib/vagrant/command/destroy.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/vagrant-1.0.5/lib/vagrant/command/destroy.rb
vagrant-1.0.5 lib/vagrant/command/destroy.rb
vagrant-1.0.4 lib/vagrant/command/destroy.rb
vagrant-1.0.3 lib/vagrant/command/destroy.rb
vagrant-1.0.2 lib/vagrant/command/destroy.rb