mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
version 0.5.8 added -c (context) options to show-method and show-doc and eval-file commands, fixed up ordering issue for options in pry command line
This commit is contained in:
parent
22d31c0b92
commit
d65a13ae30
4 changed files with 36 additions and 11 deletions
|
@ -1,3 +1,7 @@
|
|||
22/2/2010 version 0.5.8
|
||||
* Added -c (context) option to show-doc, show-methods and eval-file
|
||||
* Fixed up ordering issue of -c and -r parameters to command line pry
|
||||
|
||||
21/2/2010 version 0.5.7
|
||||
* Added pry executable, auto-loads .pryrc in user's home directory, if it
|
||||
exists.
|
||||
|
|
20
bin/pry
20
bin/pry
|
@ -9,11 +9,11 @@ rescue LoadError
|
|||
require 'rubygems'
|
||||
require 'pry'
|
||||
end
|
||||
require "optparse"
|
||||
require 'optparse'
|
||||
|
||||
# defaults
|
||||
options = {
|
||||
:context => TOPLEVEL_BINDING,
|
||||
:context_string => "TOPLEVEL_BINDING",
|
||||
:loadrc => true
|
||||
}
|
||||
|
||||
|
@ -42,22 +42,30 @@ See: `https://github.com/banister` for more information.
|
|||
|
||||
opts.on("-c", "--context CONTEXT",
|
||||
"Start the session in the specified context. Equivalent to `context.pry` in a session.") do |context|
|
||||
options[:context] = Pry.binding_for(eval(context))
|
||||
|
||||
# save the context name
|
||||
options[:context_string] = context
|
||||
end
|
||||
|
||||
opts.on_tail("-h", "--help", "This message.") do
|
||||
puts opts
|
||||
exit
|
||||
end
|
||||
end.parse!
|
||||
end.permute!
|
||||
|
||||
rcpath = File.expand_path("~/.pryrc")
|
||||
|
||||
# load ~/.pryrc, if not suppressed with -f option
|
||||
load rcpath if File.exists?(rcpath) && options[:loadrc]
|
||||
|
||||
# create the actual context
|
||||
context = Pry.binding_for(eval(options[:context_string]))
|
||||
|
||||
# execute line of code, if provided with -e option
|
||||
options[:context].eval(options[:code]) if options[:code]
|
||||
if options[:code]
|
||||
result = context.eval(options[:code])
|
||||
puts "=> #{Pry.view(result)}"
|
||||
end
|
||||
|
||||
# start the session
|
||||
options[:context].pry
|
||||
context.pry
|
||||
|
|
|
@ -237,16 +237,18 @@ Shows local and instance variables by default.
|
|||
|
||||
command "eval-file", "Eval a Ruby script. Type `eval-file --help` for more info." do |*args|
|
||||
options = {}
|
||||
target = target()
|
||||
file_name = nil
|
||||
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = %{Usage: eval-file [OPTIONS] FILE
|
||||
Eval a Ruby script at top-level or in the current context. Defaults to top-level.
|
||||
e.g: eval-file -c "hello.rb"
|
||||
Eval a Ruby script at top-level or in the specified context. Defaults to top-level.
|
||||
e.g: eval-file -c self "hello.rb"
|
||||
--
|
||||
}
|
||||
opts.on("-c", "--context", "Eval the script in the current context.") do
|
||||
opts.on("-c", "--context CONTEXT", "Eval the script in the specified context.") do |context|
|
||||
options[:c] = true
|
||||
target = Pry.binding_for(target.eval(context))
|
||||
end
|
||||
|
||||
opts.on_tail("-h", "--help", "This message.") do
|
||||
|
@ -266,8 +268,9 @@ e.g: eval-file -c "hello.rb"
|
|||
|
||||
old_constants = Object.constants
|
||||
if options[:c]
|
||||
target_self = target.eval('self')
|
||||
target.eval(File.read(file_name))
|
||||
output.puts "--\nEval'd '#{file_name}' in the current context."
|
||||
output.puts "--\nEval'd '#{file_name}' in the `#{target_self}` context."
|
||||
else
|
||||
TOPLEVEL_BINDING.eval(File.read(file_name))
|
||||
output.puts "--\nEval'd '#{file_name}' at top-level."
|
||||
|
@ -299,6 +302,7 @@ e.g: eval-file -c "hello.rb"
|
|||
|
||||
command "show-doc", "Show the comments above METH. Type `show-doc --help` for more info." do |*args|
|
||||
options = {}
|
||||
target = target()
|
||||
meth_name = nil
|
||||
|
||||
OptionParser.new do |opts|
|
||||
|
@ -311,6 +315,10 @@ e.g show-doc hello_method
|
|||
options[:M] = true
|
||||
end
|
||||
|
||||
opts.on("-c", "--context CONTEXT", "Select object context to run under.") do |context|
|
||||
target = Pry.binding_for(target.eval(context))
|
||||
end
|
||||
|
||||
opts.on_tail("-h", "--help", "This message.") do
|
||||
output.puts opts
|
||||
options[:h] = true
|
||||
|
@ -348,6 +356,7 @@ e.g show-doc hello_method
|
|||
|
||||
command "show-method", "Show the source for METH. Type `show-method --help` for more info." do |*args|
|
||||
options = {}
|
||||
target = target()
|
||||
meth_name = nil
|
||||
|
||||
OptionParser.new do |opts|
|
||||
|
@ -360,6 +369,10 @@ e.g: show-method hello_method
|
|||
options[:M] = true
|
||||
end
|
||||
|
||||
opts.on("-c", "--context CONTEXT", "Select object context to run under.") do |context|
|
||||
target = Pry.binding_for(target.eval(context))
|
||||
end
|
||||
|
||||
opts.on_tail("-h", "--help", "This message.") do
|
||||
output.puts opts
|
||||
options[:h] = true
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
class Pry
|
||||
VERSION = "0.5.7"
|
||||
VERSION = "0.5.8"
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue