`destroy` takes a `--force` flag [GH-699]
This commit is contained in:
parent
6ed6c0c085
commit
9882918903
|
@ -4,8 +4,15 @@ module Vagrant
|
||||||
module Command
|
module Command
|
||||||
class Destroy < Base
|
class Destroy < Base
|
||||||
def execute
|
def execute
|
||||||
|
options = {}
|
||||||
|
|
||||||
opts = OptionParser.new do |opts|
|
opts = OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: vagrant destroy [vm-name]"
|
opts.banner = "Usage: vagrant destroy [vm-name]"
|
||||||
|
opts.separator ""
|
||||||
|
|
||||||
|
opts.on("-f", "--force", "Destroy without confirmation.") do |f|
|
||||||
|
options[:force] = f
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the options
|
# Parse the options
|
||||||
|
@ -15,10 +22,20 @@ module Vagrant
|
||||||
@logger.debug("'Destroy' each target VM...")
|
@logger.debug("'Destroy' each target VM...")
|
||||||
with_target_vms(argv[0]) do |vm|
|
with_target_vms(argv[0]) do |vm|
|
||||||
if vm.created?
|
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",
|
choice = @env.ui.ask(I18n.t("vagrant.commands.destroy.confirmation",
|
||||||
:name => vm.name))
|
:name => vm.name))
|
||||||
|
do_destroy = choice.upcase == "Y"
|
||||||
|
end
|
||||||
|
|
||||||
if choice.upcase == "Y"
|
if do_destroy
|
||||||
@logger.info("Destroying: #{vm.name}")
|
@logger.info("Destroying: #{vm.name}")
|
||||||
vm.destroy
|
vm.destroy
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue