-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jubianchi/master
Add more formatting to redirections list
- Loading branch information
Showing
4 changed files
with
72 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,63 @@ | ||
require 'optparse' | ||
require 'json' | ||
|
||
module VagrantGetredirection | ||
class Command < Vagrant.plugin("2", :command) | ||
def execute | ||
|
||
options = {} | ||
|
||
opts = OptionParser.new do |opts| | ||
opts.banner = "Usage: vagrant redirection <vm-name>" | ||
opts.separator "" | ||
opts = OptionParser.new do |opts| | ||
opts.banner = 'Usage: vagrant redirection <name> [--json] [--port]' | ||
opts.separator '' | ||
|
||
opts.on('-j', '--json', 'Output redirections as JSON') do |j| | ||
options['json'] = j | ||
end | ||
|
||
opts.on('-p', '--port port', 'Output redirection for selected guest port') do |p| | ||
options['port'] = p | ||
end | ||
end | ||
|
||
# Parse the options | ||
argv = parse_options(opts) | ||
return if !argv | ||
|
||
contr = VagrantGetredirection::Controller.new(@app, @env) | ||
redirects = {} | ||
|
||
with_target_vms(argv, :reverse => true) do |machine| | ||
contr.run(machine, redirects) | ||
end | ||
|
||
if options['port'] | ||
|
||
redirects.each_value do |rules| | ||
rules.each_key do |guest| | ||
unless guest == options['port'] | ||
rules.delete(guest) | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Parse the options | ||
argv = parse_options(opts) | ||
return if !argv | ||
if options['json'] | ||
@env.ui.info(JSON.pretty_generate(redirects)) | ||
else | ||
redirects.each_pair do |machine, rules| | ||
if redirects.count > 1 | ||
@env.ui.info("[#{machine}] - Redirect :") | ||
end | ||
|
||
contr = VagrantGetredirection::Controller.new(@app, @env) | ||
|
||
with_target_vms(argv, :reverse => true) do |machine| | ||
contr.run(machine) | ||
rules.each_pair do |guest, host| | ||
if options['port'] | ||
@env.ui.info("#{host}") | ||
else | ||
@env.ui.info("#{host} => #{guest}") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module VagrantGetredirection | ||
VERSION = "0.2" | ||
VERSION = "0.3" | ||
end |