2011-02-20 11:54:18 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
# (C) John Mair (banisterfiend)
|
|
|
|
# MIT license
|
|
|
|
|
2011-05-03 09:58:54 -04:00
|
|
|
$0 = 'pry'
|
|
|
|
|
2011-02-20 11:54:18 -05:00
|
|
|
begin
|
|
|
|
require 'pry'
|
|
|
|
rescue LoadError
|
|
|
|
require 'rubygems'
|
|
|
|
require 'pry'
|
|
|
|
end
|
|
|
|
|
2011-09-09 01:52:47 -04:00
|
|
|
opts = Slop.parse(:help => true, :multiple_switches => false) 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.
|
2011-09-27 09:55:20 -04:00
|
|
|
See: `https://github.com/pry` for more information.
|
|
|
|
Copyright (c) 2011 John Mair (banisterfiend)
|
2011-02-20 11:54:18 -05:00
|
|
|
--
|
|
|
|
}
|
|
|
|
|
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-06-04 11:59:05 -04:00
|
|
|
|
|
|
|
on "no-pager", "Disable pager for long output" do
|
2011-09-27 09:55:20 -04:00
|
|
|
Pry.config.pager = false
|
|
|
|
end
|
|
|
|
|
|
|
|
on "no-history", "Disable history loading" do
|
|
|
|
Pry.config.history.should_load = false
|
2011-06-04 11:59:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
on "no-color", "Disable syntax highlighting for session" do
|
|
|
|
Pry.color = false
|
|
|
|
end
|
|
|
|
|
|
|
|
on :f, "Suppress loading of ~/.pryrc" do
|
|
|
|
# load ~/.pryrc, if not suppressed with -f option
|
|
|
|
Pry.config.should_load_rc = false
|
|
|
|
end
|
|
|
|
|
|
|
|
on "no-plugins", "Suppress loading of plugins." do
|
|
|
|
# suppress plugins if given --no-plugins optino
|
|
|
|
Pry.config.plugins.enabled = false
|
|
|
|
end
|
|
|
|
|
2011-09-27 09:55:20 -04:00
|
|
|
on "installed-plugins", "List installed plugins." do
|
|
|
|
puts "Installed Plugins:"
|
|
|
|
puts "--"
|
|
|
|
Pry.locate_plugins.each do |plugin|
|
|
|
|
puts "#{plugin.name}".ljust(18) + plugin.spec.summary
|
|
|
|
end
|
|
|
|
exit
|
|
|
|
end
|
2011-06-16 09:41:40 -04: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|
|
2011-07-24 23:04:44 -04:00
|
|
|
Pry.config.requires << 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-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-09-17 02:23:32 -04:00
|
|
|
if opts[:exec]
|
|
|
|
exec_string = opts[:exec] + "\n"
|
|
|
|
else
|
|
|
|
exec_string = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
# Start the session (running any code passed with -e, if there is any)
|
2011-11-02 05:37:33 -04:00
|
|
|
Pry.start(context, :input => StringIO.new(exec_string))
|
2011-02-20 11:54:18 -05:00
|
|
|
|