2011-02-20 11:54:18 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
# (C) John Mair (banisterfiend)
|
|
|
|
# MIT license
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'pry'
|
|
|
|
rescue LoadError
|
|
|
|
require 'rubygems'
|
|
|
|
require 'pry'
|
|
|
|
end
|
|
|
|
|
2011-04-24 10:33:34 -04:00
|
|
|
opts = Slop.parse(:help => true) do
|
2011-04-19 08:13:22 -04:00
|
|
|
banner %{Usage: pry [OPTIONS]
|
2011-02-20 11:54:18 -05:00
|
|
|
Start a Pry session.
|
|
|
|
See: `https://github.com/banister` for more information.
|
|
|
|
--
|
|
|
|
}
|
|
|
|
|
2011-04-19 08:13:22 -04:00
|
|
|
on :e, :exec, "A line of code to execute in context before the session starts", true
|
2011-04-24 04:47:19 -04:00
|
|
|
on :f, "Suppress loading of ~/.pryrc"
|
2011-04-19 08:13:22 -04:00
|
|
|
on "no-color", "Disable syntax highlighting for session"
|
2011-02-20 11:54:18 -05:00
|
|
|
|
2011-04-19 08:13:22 -04:00
|
|
|
on "simple-prompt", "Enable simple prompt mode" do
|
|
|
|
Pry.prompt = Pry::SIMPLE_PROMPT
|
2011-03-02 06:18:26 -05:00
|
|
|
end
|
|
|
|
|
2011-04-19 08:13:22 -04:00
|
|
|
on :r, :require, "`require` a Ruby script at startup", true do |file|
|
|
|
|
require file
|
2011-03-02 06:18:26 -05:00
|
|
|
end
|
|
|
|
|
2011-04-19 08:13:22 -04:00
|
|
|
on :I, "Add a path to the $LOAD_PATH", true do |path|
|
|
|
|
$LOAD_PATH << path
|
2011-03-02 06:18:26 -05:00
|
|
|
end
|
|
|
|
|
2011-04-19 08:13:22 -04:00
|
|
|
on :v, :version, "Display the Pry version" do
|
2011-02-20 11:54:18 -05:00
|
|
|
puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2011-04-19 08:13:22 -04:00
|
|
|
on(:c, :context,
|
|
|
|
"Start the session in the specified context. Equivalent to `context.pry` in a session.",
|
|
|
|
true,
|
|
|
|
:default => "TOPLEVEL_BINDING"
|
|
|
|
)
|
|
|
|
end
|
2011-02-20 11:54:18 -05:00
|
|
|
|
2011-03-04 07:37:59 -05:00
|
|
|
# invoked via cli
|
|
|
|
Pry.cli = true
|
2011-02-20 11:54:18 -05:00
|
|
|
|
2011-04-09 10:23:24 -04:00
|
|
|
class Pry::Commands
|
|
|
|
command "reset", "Reset the REPL to a clean state." do
|
|
|
|
output.puts "Pry reset."
|
|
|
|
exec("pry")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-20 11:54:18 -05:00
|
|
|
# load ~/.pryrc, if not suppressed with -f option
|
2011-04-19 08:13:22 -04:00
|
|
|
Pry.should_load_rc = !opts.f?
|
2011-02-20 11:54:18 -05:00
|
|
|
|
2011-02-20 19:46:29 -05:00
|
|
|
# create the actual context
|
2011-04-19 08:13:22 -04:00
|
|
|
context = Pry.binding_for(eval(opts[:context]))
|
2011-02-20 19:46:29 -05:00
|
|
|
|
2011-02-24 21:42:17 -05:00
|
|
|
# run code passed with `-e`, if there is any.
|
2011-04-19 08:13:22 -04:00
|
|
|
if opts.exec?
|
|
|
|
Pry.new(:input => StringIO.new(opts[:exec]), :print => proc {}).rep(context)
|
2011-02-20 19:46:29 -05:00
|
|
|
end
|
2011-02-20 11:54:18 -05:00
|
|
|
|
|
|
|
# start the session
|
2011-02-20 19:46:29 -05:00
|
|
|
context.pry
|