vagrant/plugins/commands/destroy/command.rb

37 lines
1001 B
Ruby
Raw Normal View History

2012-04-19 20:59:48 +00:00
module VagrantPlugins
module CommandDestroy
2012-11-07 05:05:14 +00:00
class Command < Vagrant.plugin("2", :command)
2010-08-25 06:05:40 +00:00
def execute
options = {}
options[:force] = false
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant destroy [vm-name]"
o.separator ""
o.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...")
declined = false
with_target_vms(argv, :reverse => true) do |vm|
action_env = vm.action(
:destroy, :force_confirm_destroy => options[:force])
declined = true if action_env.has_key?(:force_confirm_destroy_result) &&
action_env[:force_confirm_destroy_result] == false
2010-08-25 06:05:40 +00:00
end
# Success if no confirms were declined
declined ? 1 : 0
end
2010-08-25 06:05:40 +00:00
end
end
end