#!/usr/bin/ruby
# encoding: UTF-8

require 'tins/xt'
include Tins::GO
require 'utils/irb'
require 'drb'

def usage
  puts <<-EOT
Usage: #{File.basename($0)} [OPTS]

Options are

  -e CODE       CODE is execute on the remote irb
  -l PATH       load file PATH into remote irb context
  -u URL        druby url to connect to
  -h            display this help

Version is #{File.basename($0)} #{Utils::VERSION}.
  EOT
  exit 1
end


$opts = go 'e:u:l:h'
$opts[?h] and usage

proxy = Utils::IRB::Service.connect($opts[?u])
case
when load_path = $opts[?l]
  proxy.load(load_path)
when code = $opts[?e]
  p proxy.eval(code)
else
  puts proxy.eval(STDIN.read)
end