2015-11-24 20:48:29 +00:00
|
|
|
require "vagrant/util/presence"
|
|
|
|
|
2015-11-24 16:08:30 +00:00
|
|
|
require "optparse"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandPort
|
|
|
|
class Command < Vagrant.plugin("2", :command)
|
2015-11-24 20:48:29 +00:00
|
|
|
include Vagrant::Util::Presence
|
|
|
|
|
2015-11-24 16:08:30 +00:00
|
|
|
def self.synopsis
|
|
|
|
"displays information about guest port mappings"
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
opts = OptionParser.new do |o|
|
|
|
|
o.banner = "Usage: vagrant port [options] [name]"
|
|
|
|
o.separator ""
|
|
|
|
o.separator "Options:"
|
|
|
|
o.separator ""
|
|
|
|
|
2015-11-24 20:48:29 +00:00
|
|
|
o.on("--guest", "Output the host port that maps to the given guest port") do
|
|
|
|
end
|
|
|
|
|
2015-11-24 16:08:30 +00:00
|
|
|
o.on("--machine-readable", "Display machine-readable output")
|
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
|
|
|
|
with_target_vms(argv, single_target: true) do |vm|
|
|
|
|
vm.action_raw(:config_validate,
|
|
|
|
Vagrant::Action::Builtin::ConfigValidate)
|
|
|
|
|
|
|
|
if !vm.provider.capability?(:forwarded_ports)
|
2015-11-24 20:48:07 +00:00
|
|
|
@env.ui.error(I18n.t("port_command.missing_capability",
|
|
|
|
provider: vm.provider_name,
|
|
|
|
))
|
2015-11-24 16:08:30 +00:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
ports = vm.provider.capability(:forwarded_ports)
|
|
|
|
|
2015-11-24 20:48:29 +00:00
|
|
|
if !present?(ports)
|
2015-11-24 20:48:07 +00:00
|
|
|
@env.ui.info(I18n.t("port_command.empty_ports"))
|
2015-11-24 16:08:30 +00:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2015-11-24 20:48:07 +00:00
|
|
|
@env.ui.info(I18n.t("port_command.details"))
|
|
|
|
@env.ui.info("")
|
2015-11-24 16:08:30 +00:00
|
|
|
ports.each do |guest, host|
|
|
|
|
@env.ui.info("#{guest.to_s.rjust(6)} (guest) => #{host} (host)")
|
|
|
|
@env.ui.machine("forwarded_port", guest, host, target: vm.name.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-24 20:48:29 +00:00
|
|
|
return 0
|
2015-11-24 16:08:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|