vagrant/lib/vagrant/command/destroy.rb

55 lines
1.7 KiB
Ruby
Raw Normal View History

2011-12-17 19:05:49 +00:00
require 'optparse'
2010-08-25 06:05:40 +00:00
module Vagrant
module Command
2011-12-17 19:05:49 +00:00
class Destroy < Base
2010-08-25 06:05:40 +00:00
def execute
options = {}
2011-12-17 19:05:49 +00:00
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
2011-12-17 19:05:49 +00:00
end
# Parse the options
argv = parse_options(opts)
return if !argv
@logger.debug("'Destroy' each target VM...")
2012-02-14 18:42:30 +00:00
with_target_vms(argv[0], :reverse => true) do |vm|
2010-08-25 06:05:40 +00:00
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 = @env.ui.ask(I18n.t("vagrant.commands.destroy.confirmation",
:name => vm.name))
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
2010-08-25 06:05:40 +00:00
else
2011-12-17 19:05:49 +00:00
@logger.info("Not destroying #{vm.name}, since it isn't created.")
2011-12-27 02:14:09 +00:00
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
2010-08-25 06:05:40 +00:00
end
end
end
end
end
end