Class: PryRemote::CLI

Inherits:
Object show all
Defined in:
lib/pry-remote.rb

Overview

Parses arguments and allows to start the client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ CLI



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/pry-remote.rb', line 213

def initialize(args = ARGV)
  params = Slop.parse args, :help => true do
    banner "#$PROGRAM_NAME [OPTIONS]"

    on :s, :server=, "Host of the server (#{DefaultHost})", :argument => :optional,
       :default => DefaultHost
    on :p, :port=, "Port of the server (#{DefaultPort})", :argument => :optional,
       :as => Integer, :default => DefaultPort
    on :c, :capture, "Captures $stdout and $stderr from the server (true)",
       :default => true
    on :f, "Disables loading of .pryrc and its plugins, requires, and command history "
  end

  exit if params.help?

  @host = params[:server]
  @port = params[:port]

  @capture = params[:capture]

  Pry.initial_session_setup unless params[:f]
end

Instance Attribute Details

#captureObject (readonly) Also known as: capture?

Returns the value of attribute capture.



247
248
249
# File 'lib/pry-remote.rb', line 247

def capture
  @capture
end

#hostString (readonly)



237
238
239
# File 'lib/pry-remote.rb', line 237

def host
  @host
end

#portInteger (readonly)



240
241
242
# File 'lib/pry-remote.rb', line 240

def port
  @port
end

Instance Method Details

#run(input = Pry.config.input, output = Pry.config.output) ⇒ Object

Connects to the server



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/pry-remote.rb', line 254

def run(input = Pry.config.input, output = Pry.config.output)
  DRb.start_service
  client = DRbObject.new(nil, uri)

  input  = IOUndumpedProxy.new(input)
  output = IOUndumpedProxy.new(output)

  client.input  = input

  client.output = output

  if capture?
    client.stdout = $stdout
    client.stderr = $stderr
  end

  client.thread = Thread.current

  sleep
  DRb.stop_service
end

#uriString



243
244
245
# File 'lib/pry-remote.rb', line 243

def uri
  "druby://#{host}:#{port}"
end