Class: VagrantPlugins::VBoxSnapshot::Command::List

Inherits:
Object
  • Object
show all
Includes:
CheckRunnable
Defined in:
lib/vagrant-vbox-snapshot/commands/list.rb

Instance Method Summary collapse

Methods included from CheckRunnable

#check_runnable_on

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
32
33
# File 'lib/vagrant-vbox-snapshot/commands/list.rb', line 8

def execute
  options = {}

  opts = OptionParser.new do |opts|
    opts.banner = "List snapshots"
    opts.separator ""
    opts.separator "Usage: vagrant snapshot list"
  end
  # Parse the options
  argv = parse_options(opts)
  return if !argv

  with_target_vms(argv, single_target: true) do |machine|
    check_runnable_on(machine)
    puts "Listing snapshots for '#{machine.name}':"

    begin
      res = machine.provider.driver.execute("snapshot", machine.id, "list", "--details") do |type, data|
        @suppress_error = TRUE if data == "This machine does not have any snapshots\n"
        machine.env.ui.info(data, :color => :green) if (type == :stdout)
      end
    rescue Vagrant::Errors::VBoxManageError => e
      raise e unless @suppress_error
    end
  end
end