pry-remote 0.0.1 → 0.1.0
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/lib/pry-remote.rb +83 -7
- metadata +4 -4
data/lib/pry-remote.rb
CHANGED
@@ -2,6 +2,7 @@ require 'pry'
|
|
2
2
|
require 'slop'
|
3
3
|
require 'drb'
|
4
4
|
require 'readline'
|
5
|
+
require 'open3'
|
5
6
|
|
6
7
|
module PryRemote
|
7
8
|
# A class to represent an input object created from DRb. This is used because
|
@@ -15,8 +16,33 @@ module PryRemote
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
19
|
+
# Ensure that system (shell command) output is redirected for remote session.
|
20
|
+
System = proc do |output, cmd, _|
|
21
|
+
status = nil
|
22
|
+
Open3.popen3 cmd do |stdin, stdout, stderr, wait_thr|
|
23
|
+
stdin.close # Send EOF to the process
|
24
|
+
|
25
|
+
until stdout.eof? and stderr.eof?
|
26
|
+
ios = [stdout, stderr]
|
27
|
+
|
28
|
+
if res = IO.select([stdout, stderr])
|
29
|
+
res[0].each do |io|
|
30
|
+
next if io.eof?
|
31
|
+
output.write io.read_nonblock(1024)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
status = wait_thr.value
|
37
|
+
end
|
38
|
+
|
39
|
+
unless status.success?
|
40
|
+
output.puts "Error while executing command: #{cmd}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
18
44
|
# A client is used to retrieve information from the client program.
|
19
|
-
Client = Struct.new :input, :output, :thread do
|
45
|
+
Client = Struct.new :input, :output, :thread, :stdout, :stderr do
|
20
46
|
# Waits until both an input and output are set
|
21
47
|
def wait
|
22
48
|
sleep 0.01 until input and output and thread
|
@@ -37,16 +63,20 @@ module PryRemote
|
|
37
63
|
class CLI
|
38
64
|
def initialize(args = ARGV)
|
39
65
|
params = Slop.parse args, :help => true do
|
40
|
-
banner "#$PROGRAM_NAME [
|
66
|
+
banner "#$PROGRAM_NAME [OPTIONS]"
|
41
67
|
|
42
68
|
on :h, :host, "Host of the server (localhost)", true,
|
43
69
|
:default => "localhost"
|
44
70
|
on :p, :port, "Port of the server (9876)", true, :as => Integer,
|
45
71
|
:default => 9876
|
72
|
+
on :c, :capture, "Captures $stdout and $stderr from the server (true)",
|
73
|
+
:default => true
|
46
74
|
end
|
47
75
|
|
48
76
|
@host = params[:host]
|
49
77
|
@port = params[:port]
|
78
|
+
|
79
|
+
@capture = params[:capture]
|
50
80
|
end
|
51
81
|
|
52
82
|
# @return [String] Host of the server
|
@@ -60,6 +90,9 @@ module PryRemote
|
|
60
90
|
"druby://#{host}:#{port}"
|
61
91
|
end
|
62
92
|
|
93
|
+
attr_reader :capture
|
94
|
+
alias capture? capture
|
95
|
+
|
63
96
|
# Connects to the server
|
64
97
|
def run
|
65
98
|
DRb.start_service
|
@@ -76,6 +109,12 @@ module PryRemote
|
|
76
109
|
|
77
110
|
client.input = input
|
78
111
|
client.output = $stdout
|
112
|
+
|
113
|
+
if capture?
|
114
|
+
client.stdout = $stdout
|
115
|
+
client.stderr = $stderr
|
116
|
+
end
|
117
|
+
|
79
118
|
client.thread = Thread.current
|
80
119
|
|
81
120
|
sleep
|
@@ -98,12 +137,49 @@ class Object
|
|
98
137
|
puts "[pry-remote] Waiting for client on #{uri}"
|
99
138
|
client.wait
|
100
139
|
|
101
|
-
|
102
|
-
|
140
|
+
begin
|
141
|
+
# If client passed stdout and stderr, redirect actual messages there.
|
142
|
+
old_stdout, $stdout = if client.stdout
|
143
|
+
[$stdout, client.stdout]
|
144
|
+
else
|
145
|
+
[$stdout, $stdout]
|
146
|
+
end
|
147
|
+
|
148
|
+
old_stderr, $stderr = if client.stderr
|
149
|
+
[$stderr, client.stderr]
|
150
|
+
else
|
151
|
+
[$stderr, $stderr]
|
152
|
+
end
|
153
|
+
|
154
|
+
# Before Pry starts, save the pager config.
|
155
|
+
# We want to disable this because the pager won't do anything useful in
|
156
|
+
# this case (it will run on the server).
|
157
|
+
Pry.config.pager, old_pager = false, Pry.config.pager
|
158
|
+
|
159
|
+
# As above, but for system config
|
160
|
+
Pry.config.system, old_system = PryRemote::System, Pry.config.system
|
161
|
+
|
162
|
+
puts "[pry-remote] Client received, starting remote sesion"
|
163
|
+
Pry.start(self, :input => client.input_proxy, :output => client.output)
|
164
|
+
ensure
|
165
|
+
# Reset output streams
|
166
|
+
$stdout = old_stdout
|
167
|
+
$stderr = old_stderr
|
103
168
|
|
104
|
-
|
105
|
-
|
169
|
+
# Reset config
|
170
|
+
Pry.config.pager = old_pager
|
106
171
|
|
107
|
-
|
172
|
+
# Reset sysem
|
173
|
+
Pry.config.system = old_system
|
174
|
+
|
175
|
+
puts "[pry-remote] Remote sesion terminated"
|
176
|
+
client.kill
|
177
|
+
|
178
|
+
DRb.stop_service
|
179
|
+
end
|
108
180
|
end
|
181
|
+
|
182
|
+
# a handy alias as many people may think the method is named after the gem
|
183
|
+
# (pry-remote)
|
184
|
+
alias pry_remote remote_pry
|
109
185
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pry-remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mon ouie
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-28 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: slop
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 0.9.6
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id002
|
37
37
|
description: Connect to Pry remotely using DRb
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
requirements: []
|
70
70
|
|
71
71
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.10
|
73
73
|
signing_key:
|
74
74
|
specification_version: 3
|
75
75
|
summary: Connect to Pry remotely
|