Class: MediaWikiVagrant::ForwardPort

Inherits:
Object
  • Object
show all
Includes:
PluginEnvironment, SettingsPlugin
Defined in:
lib/mediawiki-vagrant/forward_port.rb

Overview

Configures port forwarding from the host to the guest VM.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PluginEnvironment

#initialize, #interactive_out?

Class Method Details

.synopsisObject



13
14
15
# File 'lib/mediawiki-vagrant/forward_port.rb', line 13

def self.synopsis
  'configures port forwarding from the host to the guest VM'
end

Instance Method Details

#executeObject



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
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mediawiki-vagrant/forward_port.rb', line 17

def execute
  options = {
    list: false,
    remove: []
  }

  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant forward-port [options] [host-port guest-port [...]]'
    o.separator ''
    o.separator 'Options:'
    o.separator ''

    o.on('-l', '--list', 'List currently forwarded ports') do
      options[:list] = true
    end

    o.on('-r', '--remove PORT', 'Remove forwarding for the given host port') do |port|
      options[:remove] << port
    end
  end

  argv = parse_options(opts)
  return unless argv

  if options[:list]
    list
  elsif options[:remove].any?
    remove(options[:remove].map(&:to_i))
  elsif argv.length == 2
    forward(*(argv.map(&:to_i)))
  else
    @env.ui.error opts
    return 1
  end

  0
end