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-02-20 19:46:29 -05:00
|
|
|
require 'optparse'
|
2011-02-20 11:54:18 -05:00
|
|
|
|
|
|
|
# defaults
|
|
|
|
options = {
|
2011-02-20 19:46:29 -05:00
|
|
|
:context_string => "TOPLEVEL_BINDING",
|
2011-02-20 11:54:18 -05:00
|
|
|
:loadrc => true
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionParser.new do |opts|
|
|
|
|
opts.banner = %{Usage: pry [OPTIONS]
|
|
|
|
Start a Pry session.
|
|
|
|
See: `https://github.com/banister` for more information.
|
|
|
|
--
|
|
|
|
}
|
|
|
|
opts.on("-r", "--require FILE", "`require` a Ruby script at startup.") do |file|
|
|
|
|
require file
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-e", "--exec CODE", "A line of Ruby code to execute in context before the session starts.") do |code|
|
|
|
|
options[:code] = code
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-f", "Suppress loading of ~/.pryrc") do
|
|
|
|
options[:loadrc] = false
|
|
|
|
end
|
|
|
|
|
2011-03-05 09:17:54 -05:00
|
|
|
opts.on("--no-color", "Start session without syntax highlighting.") do
|
|
|
|
Pry.color = false
|
2011-03-02 06:18:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("--simple-prompt", "Simple prompt mode.") do
|
|
|
|
Pry.prompt = Pry::SIMPLE_PROMPT
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-I LOADPATH", "Specify $LOAD_PATH directory.") do |load_path|
|
|
|
|
$LOAD_PATH << load_path
|
|
|
|
end
|
|
|
|
|
2011-02-20 11:54:18 -05:00
|
|
|
opts.on("-v", "--version", "Display the Pry version.") do
|
|
|
|
puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-c", "--context CONTEXT",
|
|
|
|
"Start the session in the specified context. Equivalent to `context.pry` in a session.") do |context|
|
2011-02-20 19:46:29 -05:00
|
|
|
|
|
|
|
# save the context name
|
|
|
|
options[:context_string] = context
|
2011-02-20 11:54:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
opts.on_tail("-h", "--help", "This message.") do
|
|
|
|
puts opts
|
|
|
|
exit
|
|
|
|
end
|
2011-02-21 08:03:42 -05:00
|
|
|
end.parse!
|
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
|
|
|
|
|
|
|
# load ~/.pryrc, if not suppressed with -f option
|
2011-03-04 07:37:59 -05:00
|
|
|
Pry.should_load_rc = false if !options[:loadrc]
|
2011-02-20 11:54:18 -05:00
|
|
|
|
2011-02-20 19:46:29 -05:00
|
|
|
# create the actual context
|
|
|
|
context = Pry.binding_for(eval(options[:context_string]))
|
|
|
|
|
2011-02-24 21:42:17 -05:00
|
|
|
# run code passed with `-e`, if there is any.
|
2011-02-20 19:46:29 -05:00
|
|
|
if options[:code]
|
2011-02-24 21:42:17 -05:00
|
|
|
Pry.new(:input => StringIO.new(options[:code]), :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
|