mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
implement whereami -n (exclude line numbers)
This commit is contained in:
parent
0608c0effa
commit
32eb6ca573
2 changed files with 26 additions and 2 deletions
|
@ -5,7 +5,7 @@ class Pry
|
|||
group 'Context'
|
||||
|
||||
banner <<-BANNER
|
||||
Usage: whereami [-q] [N]
|
||||
Usage: whereami [-qn] [N]
|
||||
|
||||
Describe the current location. If you use `binding.pry` inside a
|
||||
method then whereami will print out the source for that method.
|
||||
|
@ -17,6 +17,9 @@ class Pry
|
|||
there's no code to show. This is used by pry in the default
|
||||
before_session hook to show you when you arrive at a `binding.pry`.
|
||||
|
||||
The `-n` flag can be used to hide line numbers so that code can be copy/pasted
|
||||
effectively.
|
||||
|
||||
When pry was started on an Object and there is no associated method,
|
||||
whereami will instead output a brief description of the current
|
||||
object.
|
||||
|
@ -30,6 +33,7 @@ class Pry
|
|||
|
||||
def options(opt)
|
||||
opt.on :q, :quiet, "Don't display anything in case of an error"
|
||||
opt.on :n, :"no-line-numbers", "Do not display line numbers."
|
||||
end
|
||||
|
||||
def code
|
||||
|
@ -55,7 +59,7 @@ class Pry
|
|||
set_file_and_dir_locals(@file)
|
||||
|
||||
output.puts "\n#{text.bold('From:')} #{location}:\n\n"
|
||||
output.puts code.with_line_numbers.with_marker(@line)
|
||||
output.puts code.with_line_numbers(use_line_numbers?).with_marker(marker)
|
||||
output.puts
|
||||
end
|
||||
|
||||
|
@ -65,6 +69,14 @@ class Pry
|
|||
opts.quiet? && (internal_binding?(target) || !code?)
|
||||
end
|
||||
|
||||
def use_line_numbers?
|
||||
!opts.present?(:n)
|
||||
end
|
||||
|
||||
def marker
|
||||
!opts.present?(:n) && @line
|
||||
end
|
||||
|
||||
def top_level?
|
||||
target_self == TOPLEVEL_BINDING.eval("self")
|
||||
end
|
||||
|
|
|
@ -111,6 +111,18 @@ describe "whereami" do
|
|||
Object.remove_const(:Cor)
|
||||
end
|
||||
|
||||
it 'should not show line numbers or marker when -n switch is used' do
|
||||
class Cor
|
||||
def blimey!
|
||||
out = pry_eval(binding, 'whereami -n')
|
||||
out.should =~ /^def/
|
||||
out.should.not =~ /\=\>/
|
||||
end
|
||||
end
|
||||
Cor.new.blimey!
|
||||
Object.remove_const(:Cor)
|
||||
end
|
||||
|
||||
it 'should use Pry.config.default_window_size for window size when outside a method context' do
|
||||
old_size, Pry.config.default_window_size = Pry.config.default_window_size, 1
|
||||
:litella
|
||||
|
|
Loading…
Reference in a new issue