Class: Vagrant::Hostmaster::Command::Base

Inherits:
Command::Base
  • Object
show all
Defined in:
lib/vagrant/hostmaster/command/base.rb

Direct Known Subclasses

List, Remove, Update

Instance Method Summary collapse

Instance Method Details

#executeObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant/hostmaster/command/base.rb', line 5

def execute
  sub_command = self.class.name.split('::').last.downcase

  parser = OptionParser.new do |opts|
    opts.banner = "Usage: vagrant hosts #{sub_command} [vm-name]"
  end

  # Parse the options
  argv = parse_options(parser)
  return if !argv

  with_target_vms(argv) do |vm|
    if vm.state == :running
      Hostmaster::VM.new(vm).send sub_command.to_sym
    elsif vm.created?
      vm.ui.info I18n.t("vagrant.commands.common.vm_not_running")
    else
      vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
    end
  end

  # Success, exit status 0
  0
end