Class: VagrantPlugins::HostManager::Command

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject

Show description when ‘vagrant list-commands` is triggered



6
7
8
# File 'lib/vagrant-hostmanager/command.rb', line 6

def self.synopsis
  "plugin: vagrant-hostmanager: manages the /etc/hosts file within a multi-machine environment"
end

Instance Method Details

#executeObject



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
# File 'lib/vagrant-hostmanager/command.rb', line 10

def execute
  options = {}
  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant hostmanager [vm-name]'
    o.separator ''
    o.version = VagrantPlugins::HostManager::VERSION
    o.program_name = 'vagrant hostmanager'

    o.on('--provider provider', String,
      'Update machines with the specific provider.') do |provider|
      options[:provider] = provider.to_sym
    end
  end

  argv = parse_options(opts)
  options[:provider] ||= @env.default_provider

  # update /etc/hosts file for specified guest machines
  with_target_vms(argv, options) do |machine|
    @env.action_runner.run(Action.update_guest, {
      :global_env => @env,
      :machine => machine,
      :provider => options[:provider]
    })
  end

  # update /etc/hosts file for host
  @env.action_runner.run(Action.update_host, {
    :global_env => @env,
    :provider => options[:provider]
  })
end