pry-remote-em 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/pry-remote-em +39 -2
- data/lib/pry-remote-em/broker.rb +14 -3
- data/lib/pry-remote-em/client.rb +52 -6
- data/lib/pry-remote-em/server.rb +1 -5
- data/lib/pry-remote-em/version.rb +1 -1
- metadata +4 -4
data/bin/pry-remote-em
CHANGED
@@ -3,12 +3,49 @@
|
|
3
3
|
require 'uri'
|
4
4
|
require 'highline'
|
5
5
|
require 'pry-remote-em/client'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.on("-c", "--connect NAME", "connect to the first pry remote em server matching NAME") do |name|
|
11
|
+
options[:connect] = name
|
12
|
+
end
|
13
|
+
opts.on("-p", "--proxy NAME", "proxy through the broker to the first pry remote em server matching NAME") do |name|
|
14
|
+
options[:proxy] = name
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("--fh HOST", "--filter-host HOST", "only show servers listening at the given address (regexp)") do |host|
|
18
|
+
if host =~ /^pryems?:\/\//
|
19
|
+
ARGV.push(host)
|
20
|
+
else
|
21
|
+
options[:filter_host] = Regexp.new(host)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
opts.on("--fn NAME", "--filter-name NAME", "only show servers with a matching name (regexp)") do |name|
|
25
|
+
if name =~ /^pryems?:\/\//
|
26
|
+
ARGV.push(name)
|
27
|
+
else
|
28
|
+
options[:filter_name] = Regexp.new(name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
opts.on("--[no-]fs", "--[no-]filter-ssl", "show only servers that support ssl") do |ssl|
|
32
|
+
options[:filter_ssl] = ssl
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on('--sh', '--sort-host', 'sort by host') { options[:sort] = :host }
|
36
|
+
opts.on('--sn', '--sort-name', 'sort by server name') { |name| options[:sort] = :name }
|
37
|
+
opts.on('--sp', '--sort-port', 'sort by port') { options[:sort] = :port }
|
38
|
+
opts.on('--ss', '--sort-ssl', 'sort by ssl support') { options[:sort] = :ssl }
|
39
|
+
|
40
|
+
opts.parse!(ARGV)
|
41
|
+
end
|
6
42
|
|
7
43
|
uri = ARGV[0] || "pryem://localhost:#{PryRemoteEm::DEF_BROKERPORT}"
|
8
44
|
uri = URI.parse(uri)
|
9
45
|
unless %w(pryem pryems).include?(uri.scheme)
|
10
|
-
abort "only pryem URIs are currently supported\n usage: pryem
|
46
|
+
abort "only pryem URIs are currently supported\n usage: pryem[s]://127.0.0.1:#{PryRemoteEm::DEF_BROKERPORT}"
|
11
47
|
end
|
48
|
+
uri.port = PryRemoteEm::DEF_BROKERPORT unless uri.port
|
12
49
|
|
13
50
|
tried = 0
|
14
51
|
auth_proc = proc do
|
@@ -25,5 +62,5 @@ auth_proc = proc do
|
|
25
62
|
end
|
26
63
|
|
27
64
|
EM.run do
|
28
|
-
PryRemoteEm::Client.start(uri.host, uri.port, :auth=>auth_proc, :tls=>uri.scheme=='pryems') { |e| EM.stop }
|
65
|
+
PryRemoteEm::Client.start(uri.host, uri.port, options.merge(:auth=>auth_proc, :tls=>uri.scheme=='pryems')) { |e| EM.stop }
|
29
66
|
end
|
data/lib/pry-remote-em/broker.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'socket'
|
1
2
|
require 'pry-remote-em'
|
2
3
|
require 'pry-remote-em/client/broker'
|
3
4
|
require 'pry-remote-em/client/proxy'
|
@@ -60,11 +61,21 @@ module PryRemoteEm
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def register(url, name = 'unknown')
|
63
|
-
|
64
|
+
expand_url(url).each do |u|
|
65
|
+
client { |c| c.send_register_server(u, name) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def unregister(url)
|
70
|
+
expand_url(url).each do |u|
|
71
|
+
client { |c| c.send_unregister_server(u) }
|
72
|
+
end
|
64
73
|
end
|
65
74
|
|
66
|
-
def
|
67
|
-
|
75
|
+
def expand_url(url)
|
76
|
+
return Array(url) if (u = URI.parse(url)).host != '0.0.0.0'
|
77
|
+
Socket.ip_address_list.select { |a| a.ipv4? }
|
78
|
+
.map(&:ip_address).map{|i| u.clone.tap{|mu| mu.host = i } }
|
68
79
|
end
|
69
80
|
|
70
81
|
def watch_heartbeats(url)
|
data/lib/pry-remote-em/client.rb
CHANGED
@@ -28,6 +28,8 @@ module PryRemoteEm
|
|
28
28
|
end
|
29
29
|
end # class << self
|
30
30
|
|
31
|
+
attr_reader :opts
|
32
|
+
|
31
33
|
def initialize(opts = {})
|
32
34
|
@opts = opts
|
33
35
|
if (a = opts[:auth])
|
@@ -79,7 +81,7 @@ module PryRemoteEm
|
|
79
81
|
end
|
80
82
|
choice, proxy = choose_server(list)
|
81
83
|
return unless choice
|
82
|
-
uri, name =
|
84
|
+
uri, name = choice[0], choice[1]
|
83
85
|
if proxy
|
84
86
|
@opts[:tls] = uri.scheme == 'pryems'
|
85
87
|
@negotiated = false
|
@@ -96,10 +98,12 @@ module PryRemoteEm
|
|
96
98
|
choice = nil
|
97
99
|
nm_col_len = list.values.map(&:length).sort[-1] + 5
|
98
100
|
ur_col_len = list.keys.map(&:length).sort[-1] + 5
|
99
|
-
header = sprintf("| %-3s | %-#{nm_col_len}s | %-#{ur_col_len}s |", "
|
101
|
+
header = sprintf("| %-3s | %-#{nm_col_len}s | %-#{ur_col_len}s |", "", "name", "url")
|
100
102
|
border = ("-" * header.length)
|
101
103
|
table = [border, header, border]
|
102
|
-
list = list.to_a
|
104
|
+
list = list.to_a.map{|url, name| [URI.parse(url), name]}
|
105
|
+
list = filter_server_list(list)
|
106
|
+
list = sort_server_list(list)
|
103
107
|
list.each_with_index do |(url, name), idx|
|
104
108
|
table << sprintf("| %-2d | %-#{nm_col_len}s | %-#{ur_col_len}s |", idx + 1, name, url)
|
105
109
|
end
|
@@ -112,7 +116,13 @@ module PryRemoteEm
|
|
112
116
|
else
|
113
117
|
question = "(q) to quit; (r) to refresh (p) to proxy\nconnect to: "
|
114
118
|
end
|
115
|
-
choice =
|
119
|
+
if (choice = opts.delete(:proxy))
|
120
|
+
proxy = true
|
121
|
+
else
|
122
|
+
choice = opts.delete(:connect) || highline.ask(question)
|
123
|
+
proxy = false
|
124
|
+
end
|
125
|
+
|
116
126
|
return close_connection if ['q', 'quit', 'exit'].include?(choice.downcase)
|
117
127
|
if ['r', 'reload', 'refresh'].include?(choice.downcase)
|
118
128
|
send_server_list
|
@@ -128,13 +138,49 @@ module PryRemoteEm
|
|
128
138
|
choice = nil
|
129
139
|
next
|
130
140
|
end
|
131
|
-
choice = choice.to_i
|
141
|
+
choice = choice.to_i > 0 ?
|
132
142
|
list[choice.to_i - 1] :
|
133
|
-
list.find{|(url, name)| url == choice || name == choice }
|
143
|
+
list.find{|(url, name)| url.to_s == choice || name == choice }
|
144
|
+
log.error("\033[31mserver not found\033[0m") unless choice
|
134
145
|
end
|
135
146
|
[choice, proxy]
|
136
147
|
end
|
137
148
|
|
149
|
+
def sort_server_list(list)
|
150
|
+
type = opts[:sort] || :host
|
151
|
+
case type
|
152
|
+
when :name
|
153
|
+
list.sort { |a,b| a[1] <=> b[1] }
|
154
|
+
when :host
|
155
|
+
list.sort { |a,b| a[0].host <=> b[0].host }
|
156
|
+
when :ssl
|
157
|
+
list.sort { |a,b| b[0].scheme <=> a[0].scheme }
|
158
|
+
when :port
|
159
|
+
list.sort { |a,b| a[0].port <=> b[0].port }
|
160
|
+
else
|
161
|
+
list.sort { |a,b| a[0].host <=> b[0].host }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def filter_server_list(list)
|
166
|
+
if opts[:filter_host]
|
167
|
+
list = list.select { |url, name| url.host =~ opts[:filter_host] }
|
168
|
+
end
|
169
|
+
if opts[:filter_name]
|
170
|
+
list = list.select { |url, name| name =~ opts[:filter_name] }
|
171
|
+
end
|
172
|
+
if opts.include?(:filter_ssl)
|
173
|
+
list = opts[:filter_ssl] ?
|
174
|
+
list.select{|url, name| url.scheme == 'pryems' } :
|
175
|
+
list.select{|url, name| url.scheme == 'pryem' }
|
176
|
+
end
|
177
|
+
if list.empty?
|
178
|
+
log.info("\033[33m[pry-remote-em] no registered servers match the given filter\033[0m")
|
179
|
+
Process.exit
|
180
|
+
end
|
181
|
+
list
|
182
|
+
end
|
183
|
+
|
138
184
|
def receive_auth(a)
|
139
185
|
return fail a if a.is_a?(String)
|
140
186
|
return authenticate if a == false
|
data/lib/pry-remote-em/server.rb
CHANGED
@@ -100,11 +100,7 @@ module PryRemoteEm
|
|
100
100
|
raise "can't bind to #{host}:#{port} - #{e}"
|
101
101
|
end
|
102
102
|
url = "#{opts[:tls] ? 'pryems' : 'pryem'}://#{host}:#{port}/"
|
103
|
-
|
104
|
-
name = obj.send(:eval, 'self')
|
105
|
-
rescue
|
106
|
-
name = "#{obj}"
|
107
|
-
end
|
103
|
+
name = obj.send(:eval, 'self') rescue "#{obj}"
|
108
104
|
name = Pry.view_clip(name)
|
109
105
|
PryRemoteEm.servers[url] = [server, name]
|
110
106
|
(opts[:logger] || ::Logger.new(STDERR)).info("[pry-remote-em] listening for connections on #{url}")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-remote-em
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.9
|
37
|
+
version: '0.9'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.9
|
45
|
+
version: '0.9'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: ruby-termios
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|