class CLI
Parses arguments and allows to start the client.
Attributes
bind[R]
@return [String] Bind for local DRab server
capture[R]
capture?[R]
host[R]
@return [String] Host of the server
persist[R]
persist?[R]
port[R]
@return [Integer] Port of the server
unix[R]
@return [String] Unix domain socket path of the server
uri[R]
@return [String] URI for DRab
wait[R]
wait?[R]
Public Class Methods
new(args = ARGV)
click to toggle source
# File lib/pray-remote/pray-remote.rb, line 412 def initialize(args = ARGV) params = Slop.parse args, :help => true do banner "#$PROGRAM_NAME [OPTIONS]" on :s, :server=, "Host of the server (#{DefaultHost})", :argument => true, :default => DefaultHost on :p, :port=, "Port of the server (#{DefaultPort})", :argument => true, :as => Integer, :default => DefaultPort on :w, :wait, "Wait for the pry server to come up", :default => false on :r, :persist, "Persist the client to wait for the pry server to come up each time", :default => false on :c, :capture=, "Captures $stdout and $stderr from the server (true)", :argument => true, :default => true on :f, "Disables loading of .pryrc and its plugins, requires, and command history " on :b, :bind=, "Local Drb bind (IP open to server and random port by default, or a Unix domain socket path)" on :z, :bind_proto=, "Protocol for bind to override connection-based default (tcp or unix)" on :u, :unix=, "Unix domain socket path of the server" on :k, :secret=, "Shared secret for authenticating to the server (TCP only)" end exit if params.help? @host = params[:server] @port = params[:port] @bind = params[:bind] @bind_proto = params[:bind_proto] @unix = params[:unix] @secret = "" if params[:secret] != nil #@secret = "?secret=" + params[:secret] @secret = params[:secret] end if @bind_proto == nil if @unix == nil @bind_proto = "druby://" else @bind_proto = "drabunix:" end else if @bind_proto == "tcp" elsif @bind_proto == "unix" else STDOUT.puts "[pry-remote] invalid bind protocol" exit end end if @unix == nil @uri = "druby://#{@host}:#{@port}" #@uri = "druby://#{@host}:#{@port}#{@secret}" @unix = "" else if @bind == nil STDOUT.puts "[pry-remote] bind not supplied for Unix domain socket connection" exit end @uri = "drabunix:#{@unix}" end @wait = params[:wait] @persist = params[:persist] @capture = params[:capture] === "false" ? false : params[:capture] Pry.initial_session_setup unless params[:f] end
Public Instance Methods
connect(input = Pry.config.input, output = Pry.config.output)
click to toggle source
Connects to the server
@param [IO] input Object
holding input for pry-remote @param [IO] output Object
pry-debug will send its output to
# File lib/pray-remote/pray-remote.rb, line 494 def connect(input = Pry.config.input, output = Pry.config.output) secret_str = @secret != "" ? "?secret=#{@secret}" : "" if bind == false local_ip = UDPSocket.open {|s| s.connect(@host, 1); s.addr.last} DRab.start_service "druby://#{local_ip}:0#{secret_str}" else if @bind_proto == "tcp" DRab.start_service "druby://#{bind}#{secret_str}" else DRab.start_service "drabunix:#{bind}#{secret_str}" end end $client = DRabObject.new(nil, uri) begin $client.input = IOUndumpedProxy.new(input) $client.output = IOUndumpedProxy.new(output) rescue DRab::DRabConnError => ex if wait? || persist? sleep 1 retry else raise ex end end if capture? $client.stdout = StdoeWrapper.new($stdout) $client.stderr = StdoeWrapper.new($stderr) end $client.thread = ThreadWrapper.new(Thread.current) # solved by using own object mapper, leaving this here though for future reference #GC.disable # spooky stuff happens causing the client to garbage collect the StdoeWrappers # currently not able to properly pass :control_c/emulate it # just preventing accidental close for now def set_trap Signal.trap("INT") do begin #Thread.new { # begin # puts $client.mypry.repl.to_s # $client.mypry.repl.output.puts "" # $client.mypry.reset_eval_string # rescue Exception => e # puts e # puts e.backtrace # end #} Thread.new { begin $client.mypry.to_s rescue Exception => e exit(1) end } rescue Exception => e puts e puts e.backtrace end set_trap end end begin set_trap sleep ensure DRab.stop_service end end
run()
click to toggle source
# File lib/pray-remote/pray-remote.rb, line 483 def run while true connect break unless persist? end end
set_trap()
click to toggle source
currently not able to properly pass :control_c/emulate it just preventing accidental close for now
# File lib/pray-remote/pray-remote.rb, line 534 def set_trap Signal.trap("INT") do begin #Thread.new { # begin # puts $client.mypry.repl.to_s # $client.mypry.repl.output.puts "" # $client.mypry.reset_eval_string # rescue Exception => e # puts e # puts e.backtrace # end #} Thread.new { begin $client.mypry.to_s rescue Exception => e exit(1) end } rescue Exception => e puts e puts e.backtrace end set_trap end end