Class: VagrantPlugins::Down::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-down/plugin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



19
20
21
# File 'lib/vagrant-down/plugin.rb', line 19

def self.synopsis
  'alias for destroy command'
end

Instance Method Details

#executeObject



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
52
53
# File 'lib/vagrant-down/plugin.rb', line 23

def execute
  options = {
    force: false
  }

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

    o.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...")
  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
  end

  # Success if no confirms were declined
  declined ? 1 : 0
end