Class: Vagrant::Nuke::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-nuke/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



4
5
6
# File 'lib/vagrant-nuke/command.rb', line 4

def self.synopsis
  "remove all boxes under vagrant box list."
end

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-nuke/command.rb', line 8

def execute
  options = {}
  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant nuke [options]'
    o.separator ""
    o.separator "Options:"
    o.separator ""
    o.on("-w","--whatif", "Displays all boxes that would be removed") do |i|
      options[:whatif] = i
    end
  end

  args = parse_options(opts)
  return if !args

  boxes = @env.boxes.all.sort
  if boxes.empty?
    return @env.ui.warn("no boxes found")
  end

  nuke_boxes(boxes, options[:whatif])
  #exit as 0 great success!
  0
end

#nuke_boxes(boxes, whatif) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant-nuke/command.rb', line 33

def nuke_boxes(boxes, whatif)
  if whatif
    @env.ui.info("These would have been nuked")
    boxes.each do |name, version, provider|
      @env.ui.info("#{name} #{version}")
    end
  elsif
    boxes.each do |name, version, provider|
      @env.ui.info("#{name} #{version}")
      @env.action_runner.run(Vagrant::Action.action_box_remove, {
        box_name:                 name,
        box_version:              version,
        force_confirm_box_remove: true,
      })
    end
  end
end