mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Merge branch 'dev' of github.com:banister/pry into feature/history-array
Conflicts: lib/pry/pry_instance.rb
This commit is contained in:
commit
25d7a793ac
14 changed files with 79 additions and 36 deletions
|
@ -11,8 +11,9 @@ class Pry
|
||||||
attr_accessor :command_set
|
attr_accessor :command_set
|
||||||
attr_accessor :command_processor
|
attr_accessor :command_processor
|
||||||
|
|
||||||
def run(name, *args)
|
def run(command_string, *args)
|
||||||
command_set.run_command(self, name, *args)
|
complete_string = "#{command_string} #{args.join(" ")}"
|
||||||
|
command_processor.process_commands(complete_string, eval_string, target)
|
||||||
end
|
end
|
||||||
|
|
||||||
def commands
|
def commands
|
||||||
|
|
|
@ -112,8 +112,8 @@ class Pry
|
||||||
gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
|
gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
|
||||||
|
|
||||||
options[:stub_info] = proc do
|
options[:stub_info] = proc do
|
||||||
output.puts "\n#{name} requires the following gems to be installed: #{(gems_needed.join(", "))}"
|
output.puts "\nThe command '#{name}' is unavailable because it requires the following gems to be installed: #{(gems_not_installed.join(", "))}"
|
||||||
output.puts "Command not available due to dependency on gems: `#{gems_not_installed.join(", ")}` not being met."
|
output.puts "-"
|
||||||
output.puts "Type `install #{name}` to install the required gems and activate this command."
|
output.puts "Type `install #{name}` to install the required gems and activate this command."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -257,6 +257,16 @@ class Pry
|
||||||
next if gem_install_failed
|
next if gem_install_failed
|
||||||
|
|
||||||
Gem.refresh
|
Gem.refresh
|
||||||
|
gems_to_install.each do |g|
|
||||||
|
begin
|
||||||
|
require g
|
||||||
|
rescue LoadError
|
||||||
|
output.puts "Required Gem: `#{g}` installed but not found?!. Aborting command installation."
|
||||||
|
gem_install_failed = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
next if gem_install_failed
|
||||||
|
|
||||||
command.options.delete :stub_info
|
command.options.delete :stub_info
|
||||||
output.puts "Installation of `#{name}` successful! Type `help #{name}` for information"
|
output.puts "Installation of `#{name}` successful! Type `help #{name}` for information"
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,6 +70,17 @@ class Pry
|
||||||
# Determines whether plugins should be loaded.
|
# Determines whether plugins should be loaded.
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
attr_accessor :should_load_plugins
|
attr_accessor :should_load_plugins
|
||||||
|
|
||||||
|
# Config option for history.
|
||||||
|
# sub-options include hist.file, hist.load, and hist.save
|
||||||
|
# hist.file is the file to save/load history too, e.g
|
||||||
|
# Pry.config.history.file = "~/.pry_history".
|
||||||
|
# hist.load is a boolean that determines whether history will be
|
||||||
|
# loaded from hist.file at session start.
|
||||||
|
# hist.save is a boolean that determines whether history will be
|
||||||
|
# saved to hist.file at session end.
|
||||||
|
# @return [OpenStruct]
|
||||||
|
attr_accessor :history
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ class Object
|
||||||
begin
|
begin
|
||||||
instance_eval %{
|
instance_eval %{
|
||||||
def __binding_impl__
|
def __binding_impl__
|
||||||
binding
|
Kernel.binding
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
rescue TypeError
|
rescue TypeError
|
||||||
self.class.class_eval %{
|
self.class.class_eval %{
|
||||||
def __binding_impl__
|
def __binding_impl__
|
||||||
binding
|
Kernel.binding
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,9 +10,9 @@ class Pry
|
||||||
command "simple-prompt", "Toggle the simple prompt." do
|
command "simple-prompt", "Toggle the simple prompt." do
|
||||||
case Pry.active_instance.prompt
|
case Pry.active_instance.prompt
|
||||||
when Pry::SIMPLE_PROMPT
|
when Pry::SIMPLE_PROMPT
|
||||||
Pry.active_instance.prompt = Pry::DEFAULT_PROMPT
|
Pry.active_instance.pop_prompt
|
||||||
else
|
else
|
||||||
Pry.active_instance.prompt = Pry::SIMPLE_PROMPT
|
Pry.active_instance.push_prompt Pry::SIMPLE_PROMPT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Pry
|
||||||
TOPLEVEL_BINDING.pry
|
TOPLEVEL_BINDING.pry
|
||||||
next
|
next
|
||||||
else
|
else
|
||||||
Pry.start target.eval(opts[:arg_string])
|
Pry.start target.eval(arg_string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,16 +54,14 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
command "exit", "End the current Pry session. Accepts optional return value. Aliases: quit, back" do
|
command "exit", "End the current Pry session. Accepts optional return value. Aliases: quit, back" do
|
||||||
str = remove_first_word(opts[:val])
|
throw(:breakout, [opts[:nesting].level, target.eval(arg_string)])
|
||||||
throw(:breakout, [opts[:nesting].level, target.eval(str)])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_command "quit", "exit", ""
|
alias_command "quit", "exit", ""
|
||||||
alias_command "back", "exit", ""
|
alias_command "back", "exit", ""
|
||||||
|
|
||||||
command "exit-all", "End all nested Pry sessions. Accepts optional return value. Aliases: !!@" do
|
command "exit-all", "End all nested Pry sessions. Accepts optional return value. Aliases: !!@" do
|
||||||
str = remove_first_word(opts[:val])
|
throw(:breakout, [0, target.eval(arg_string)])
|
||||||
throw(:breakout, [0, target.eval(str)])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_command "!!@", "exit-all", ""
|
alias_command "!!@", "exit-all", ""
|
||||||
|
@ -76,7 +74,7 @@ class Pry
|
||||||
alias_command "!!!", "exit-program", ""
|
alias_command "!!!", "exit-program", ""
|
||||||
|
|
||||||
command "!pry", "Start a Pry session on current self; this even works mid-expression." do
|
command "!pry", "Start a Pry session on current self; this even works mid-expression." do
|
||||||
Pry.start(target)
|
target.pry
|
||||||
end
|
end
|
||||||
|
|
||||||
command "whereami", "Show the code context for the session. (whereami <n> shows <n> extra lines of code around the invocation line. Default: 5)" do |num|
|
command "whereami", "Show the code context for the session. (whereami <n> shows <n> extra lines of code around the invocation line. Default: 5)" do |num|
|
||||||
|
|
|
@ -62,6 +62,14 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opt.on :s, :show, 'Show the history corresponding to the history line (or range of lines).', true, :as => Range do |range|
|
||||||
|
unless opt.grep?
|
||||||
|
start_line = range.is_a?(Range) ? range.first : range
|
||||||
|
lines = text.with_line_numbers Array(history[range]).join("\n"), start_line
|
||||||
|
stagger_output lines
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
opt.on :e, :exclude, 'Exclude pry commands from the history.' do
|
opt.on :e, :exclude, 'Exclude pry commands from the history.' do
|
||||||
unless opt.grep?
|
unless opt.grep?
|
||||||
history.map!.with_index do |element, index|
|
history.map!.with_index do |element, index|
|
||||||
|
|
|
@ -4,14 +4,14 @@ class Pry
|
||||||
Experimental = Pry::CommandSet.new do
|
Experimental = Pry::CommandSet.new do
|
||||||
|
|
||||||
|
|
||||||
command /rue-(\d)/, "Experimental amend-line, where the N in rue-N represents line to replace", :interpolate => false do |replacement_line|
|
command "reload-method", "Reload the source specifically for a method", :requires_gem => "method_reload" do |meth_name|
|
||||||
replacement_line = "" if !replacement_line
|
if (meth = get_method_object(meth_name, target, {})).nil?
|
||||||
input_array = opts[:eval_string].each_line.to_a
|
output.puts "Invalid method name: #{meth_name}."
|
||||||
line_number = opts[:captures].first.to_i
|
next
|
||||||
input_array[line_number] = opts[:arg_string] + "\n"
|
end
|
||||||
opts[:eval_string].replace input_array.join
|
|
||||||
end
|
|
||||||
|
|
||||||
|
meth.reload
|
||||||
|
end
|
||||||
|
|
||||||
command "play-string", "Play a string as input" do
|
command "play-string", "Play a string as input" do
|
||||||
Pry.active_instance.input = StringIO.new(opts[:arg_string])
|
Pry.active_instance.input = StringIO.new(opts[:arg_string])
|
||||||
|
|
|
@ -14,10 +14,6 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_first_word(text)
|
|
||||||
text.split.drop(1).join(' ')
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_command(name)
|
def find_command(name)
|
||||||
command_match = commands.find { |_, command| command.options[:listing] == name }
|
command_match = commands.find { |_, command| command.options[:listing] == name }
|
||||||
|
|
||||||
|
@ -49,8 +45,10 @@ class Pry
|
||||||
gems_needed = Array(options[:requires_gem])
|
gems_needed = Array(options[:requires_gem])
|
||||||
gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
|
gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
|
||||||
proc do
|
proc do
|
||||||
output.puts "\n#{name} requires the following gems to be installed: #{(gems_needed.join(", "))}"
|
output.puts "\nThe command '#{name}' requires the following gems to be installed: #{(gems_needed.join(", "))}"
|
||||||
|
output.puts "-"
|
||||||
output.puts "Command not available due to dependency on gems: `#{gems_not_installed.join(", ")}` not being met."
|
output.puts "Command not available due to dependency on gems: `#{gems_not_installed.join(", ")}` not being met."
|
||||||
|
output.puts "-"
|
||||||
output.puts "Type `install #{name}` to install the required gems and activate this command."
|
output.puts "Type `install #{name}` to install the required gems and activate this command."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,11 +48,6 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_first_word(text)
|
|
||||||
text.split.drop(1).join(' ')
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def code_and_code_type_for(meth)
|
def code_and_code_type_for(meth)
|
||||||
case code_type = code_type_for(meth)
|
case code_type = code_type_for(meth)
|
||||||
when nil
|
when nil
|
||||||
|
|
|
@ -96,8 +96,8 @@ class Pry
|
||||||
# we only want them loaded once per entire Pry lifetime, not
|
# we only want them loaded once per entire Pry lifetime, not
|
||||||
# multiple times per each new session (i.e in debugging)
|
# multiple times per each new session (i.e in debugging)
|
||||||
load_rc if Pry.config.should_load_rc
|
load_rc if Pry.config.should_load_rc
|
||||||
load_history if Pry.config.history.load
|
|
||||||
load_plugins if Pry.config.should_load_plugins
|
load_plugins if Pry.config.should_load_plugins
|
||||||
|
load_history if Pry.config.history.load
|
||||||
|
|
||||||
@initial_session = false
|
@initial_session = false
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
require "pry/command_processor.rb"
|
require "pry/command_processor.rb"
|
||||||
|
|
||||||
# @attr prompt
|
|
||||||
class Pry
|
class Pry
|
||||||
|
|
||||||
attr_accessor :input
|
attr_accessor :input
|
||||||
|
@ -81,7 +80,7 @@ class Pry
|
||||||
self.class.nesting = v
|
self.class.nesting = v
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Boolean] Whether current session is the top-level session.
|
# @return [Boolean] Whether top-level session has ended.
|
||||||
def finished_top_level_session?
|
def finished_top_level_session?
|
||||||
nesting.empty?
|
nesting.empty?
|
||||||
end
|
end
|
||||||
|
@ -243,7 +242,7 @@ class Pry
|
||||||
eval_string
|
eval_string
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME should delete this method? it's exposing an implementation detail!
|
# Output the result or pass to an exception handler (if result is an exception).
|
||||||
def show_result(result)
|
def show_result(result)
|
||||||
if last_result_is_exception?
|
if last_result_is_exception?
|
||||||
exception_handler.call output, result
|
exception_handler.call output, result
|
||||||
|
@ -364,7 +363,8 @@ class Pry
|
||||||
|
|
||||||
# Save readline history to a file.
|
# Save readline history to a file.
|
||||||
def save_history
|
def save_history
|
||||||
File.open Pry.config.history.file, 'w' do |f|
|
history_file = File.expand_path(Pry.config.history.file)
|
||||||
|
File.open(history_file, 'w') do |f|
|
||||||
f.write Readline::HISTORY.to_a.join("\n")
|
f.write Readline::HISTORY.to_a.join("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,6 +98,23 @@ describe "Pry::Commands" do
|
||||||
str_output.string.each_line.count.should == 4
|
str_output.string.each_line.count.should == 4
|
||||||
str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/
|
str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# strangeness in this test is due to bug in Readline::HISTORY not
|
||||||
|
# always registering first line of input
|
||||||
|
it 'should show lines between lines A and B with the --show switch' do
|
||||||
|
push_first_hist_line.call(@hist, "0")
|
||||||
|
("a".."z").each do |v|
|
||||||
|
@hist.push v
|
||||||
|
end
|
||||||
|
|
||||||
|
str_output = StringIO.new
|
||||||
|
redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do
|
||||||
|
pry
|
||||||
|
end
|
||||||
|
|
||||||
|
str_output.string.each_line.count.should == 4
|
||||||
|
str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "show-method" do
|
describe "show-method" do
|
||||||
|
|
|
@ -297,6 +297,11 @@ describe Pry do
|
||||||
Pry.binding_for(_main_.call).should == TOPLEVEL_BINDING
|
Pry.binding_for(_main_.call).should == TOPLEVEL_BINDING
|
||||||
Pry.binding_for(_main_.call).should == Pry.binding_for(_main_.call)
|
Pry.binding_for(_main_.call).should == Pry.binding_for(_main_.call)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should return a binding with the right self for procs' do
|
||||||
|
proc = Proc.new {}
|
||||||
|
Pry.binding_for(proc).eval("self").should.equal? proc
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue