show-method and show-doc now accept multiple method names
fixes
This commit is contained in:
parent
0e119555de
commit
2b70a27f1f
|
@ -11,7 +11,7 @@ class Pry
|
||||||
target = target()
|
target = target()
|
||||||
|
|
||||||
opts = Slop.parse!(args) do |opt|
|
opts = Slop.parse!(args) do |opt|
|
||||||
opt.banner = "Usage: show-doc [OPTIONS] [METH]\n" \
|
opt.banner = "Usage: show-doc [OPTIONS] [METH 1] [METH 2] [METH N]\n" \
|
||||||
"Show the comments above method METH. Tries instance methods first and then methods by default.\n" \
|
"Show the comments above method METH. Tries instance methods first and then methods by default.\n" \
|
||||||
"e.g show-doc hello_method"
|
"e.g show-doc hello_method"
|
||||||
|
|
||||||
|
@ -28,25 +28,28 @@ class Pry
|
||||||
|
|
||||||
next if opts.help?
|
next if opts.help?
|
||||||
|
|
||||||
meth_name = args.shift
|
args = [nil] if args.empty?
|
||||||
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
|
args.each do |method_name|
|
||||||
output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help"
|
meth_name = method_name
|
||||||
next
|
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
|
||||||
end
|
output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help"
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
doc, code_type = doc_and_code_type_for(meth)
|
doc, code_type = doc_and_code_type_for(meth)
|
||||||
next if !doc
|
next if !doc
|
||||||
|
|
||||||
next output.puts("No documentation found.") if doc.empty?
|
next output.puts("No documentation found.") if doc.empty?
|
||||||
doc = process_comment_markup(doc, code_type)
|
doc = process_comment_markup(doc, code_type)
|
||||||
output.puts make_header(meth, code_type, doc)
|
output.puts make_header(meth, code_type, doc)
|
||||||
output.puts "#{text.bold("visibility: ")} #{method_visibility(meth).to_s}"
|
output.puts "#{text.bold("visibility: ")} #{method_visibility(meth).to_s}"
|
||||||
if meth.respond_to?(:parameters)
|
if meth.respond_to?(:parameters)
|
||||||
output.puts "#{text.bold("signature: ")} #{signature_for(meth)}"
|
output.puts "#{text.bold("signature: ")} #{signature_for(meth)}"
|
||||||
output.puts
|
output.puts
|
||||||
|
end
|
||||||
|
render_output(opts.flood?, false, doc)
|
||||||
|
doc
|
||||||
end
|
end
|
||||||
render_output(opts.flood?, false, doc)
|
|
||||||
doc
|
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_command "?", "show-doc", ""
|
alias_command "?", "show-doc", ""
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Pry
|
||||||
target = target()
|
target = target()
|
||||||
|
|
||||||
opts = Slop.parse!(args) do |opt|
|
opts = Slop.parse!(args) do |opt|
|
||||||
opt.banner "Usage: show-method [OPTIONS] [METH]\n" \
|
opt.banner "Usage: show-method [OPTIONS] [METH 1] [METH 2] [METH N]\n" \
|
||||||
"Show the source for method METH. Tries instance methods first and then methods by default.\n" \
|
"Show the source for method METH. Tries instance methods first and then methods by default.\n" \
|
||||||
"e.g: show-method hello_method"
|
"e.g: show-method hello_method"
|
||||||
|
|
||||||
|
@ -29,30 +29,33 @@ class Pry
|
||||||
|
|
||||||
next if opts.help?
|
next if opts.help?
|
||||||
|
|
||||||
meth_name = args.shift
|
args = [nil] if args.empty?
|
||||||
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
|
args.each do |method_name|
|
||||||
output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help"
|
meth_name = method_name
|
||||||
next
|
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
|
||||||
|
output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help"
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
code, code_type = code_and_code_type_for(meth)
|
||||||
|
next if !code
|
||||||
|
|
||||||
|
output.puts make_header(meth, code_type, code)
|
||||||
|
if Pry.color
|
||||||
|
code = CodeRay.scan(code, code_type).term
|
||||||
|
end
|
||||||
|
|
||||||
|
start_line = false
|
||||||
|
if opts.l?
|
||||||
|
start_line = meth.source_location ? meth.source_location.last : 1
|
||||||
|
end
|
||||||
|
|
||||||
|
start_line = opts.b? ? 1 : start_line
|
||||||
|
|
||||||
|
|
||||||
|
render_output(opts.flood?, start_line, code)
|
||||||
|
code
|
||||||
end
|
end
|
||||||
|
|
||||||
code, code_type = code_and_code_type_for(meth)
|
|
||||||
next if !code
|
|
||||||
|
|
||||||
output.puts make_header(meth, code_type, code)
|
|
||||||
if Pry.color
|
|
||||||
code = CodeRay.scan(code, code_type).term
|
|
||||||
end
|
|
||||||
|
|
||||||
start_line = false
|
|
||||||
if opts.l?
|
|
||||||
start_line = meth.source_location ? meth.source_location.last : 1
|
|
||||||
end
|
|
||||||
|
|
||||||
start_line = opts.b? ? 1 : start_line
|
|
||||||
|
|
||||||
|
|
||||||
render_output(opts.flood?, start_line, code)
|
|
||||||
code
|
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_command "show-source", "show-method", ""
|
alias_command "show-source", "show-method", ""
|
||||||
|
|
|
@ -32,6 +32,11 @@ def sample_method
|
||||||
:sample
|
:sample
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# another sample doc
|
||||||
|
def another_sample_method
|
||||||
|
:another_sample
|
||||||
|
end
|
||||||
|
|
||||||
def redirect_pry_io(new_in, new_out)
|
def redirect_pry_io(new_in, new_out)
|
||||||
old_in = Pry.input
|
old_in = Pry.input
|
||||||
old_out = Pry.output
|
old_out = Pry.output
|
||||||
|
|
|
@ -11,6 +11,16 @@ describe "Pry::DefaultCommands::Documentation" do
|
||||||
str_output.string.should =~ /sample doc/
|
str_output.string.should =~ /sample doc/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should output multiple methods\' documentation' do
|
||||||
|
str_output = StringIO.new
|
||||||
|
redirect_pry_io(InputTester.new("show-doc sample_method another_sample_method", "exit-all"), str_output) do
|
||||||
|
pry
|
||||||
|
end
|
||||||
|
|
||||||
|
str_output.string.should =~ /sample doc/
|
||||||
|
str_output.string.should =~ /another sample doc/
|
||||||
|
end
|
||||||
|
|
||||||
it 'should output a method\'s documentation if inside method without needing to use method name' do
|
it 'should output a method\'s documentation if inside method without needing to use method name' do
|
||||||
$str_output = StringIO.new
|
$str_output = StringIO.new
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,16 @@ describe "Pry::DefaultCommands::Introspection" do
|
||||||
str_output.string.should =~ /def sample/
|
str_output.string.should =~ /def sample/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should output multiple methods\' sources' do
|
||||||
|
str_output = StringIO.new
|
||||||
|
redirect_pry_io(InputTester.new("show-method sample_method another_sample_method", "exit-all"), str_output) do
|
||||||
|
pry
|
||||||
|
end
|
||||||
|
|
||||||
|
str_output.string.should =~ /def sample/
|
||||||
|
str_output.string.should =~ /def another_sample/
|
||||||
|
end
|
||||||
|
|
||||||
it 'should output a method\'s source with line numbers' do
|
it 'should output a method\'s source with line numbers' do
|
||||||
str_output = StringIO.new
|
str_output = StringIO.new
|
||||||
redirect_pry_io(InputTester.new("show-method -l sample_method", "exit-all"), str_output) do
|
redirect_pry_io(InputTester.new("show-method -l sample_method", "exit-all"), str_output) do
|
||||||
|
|
Loading…
Reference in New Issue