Class: Vagrant::Command::Destroy
- Defined in:
- lib/vagrant/command/destroy.rb
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Vagrant::Command::Base
Instance Method Details
#execute ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vagrant/command/destroy.rb', line 6 def execute = {} opts = OptionParser.new do |opts| opts. = "Usage: vagrant destroy [vm-name]" opts.separator "" opts.on("-f", "--force", "Destroy without confirmation.") do |f| [:force] = f end end # Parse the options argv = (opts) return if !argv @logger.debug("'Destroy' each target VM...") with_target_vms(argv[0], :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 [: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 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 end |