parent
7fe9fc1fd5
commit
6512d82b7f
|
@ -26,7 +26,7 @@ class Pry
|
|||
output.puts "#{text.bold("Visibility:")} #{meth.visibility}"
|
||||
output.puts "#{text.bold("Signature:")} #{meth.signature}"
|
||||
output.puts
|
||||
render_output(opts.flood?, false, doc)
|
||||
render_output(opts.present?(:flood), false, doc)
|
||||
end
|
||||
|
||||
alias_command "?", "show-doc"
|
||||
|
@ -74,7 +74,7 @@ class Pry
|
|||
end
|
||||
|
||||
type_map = { :ruby => "rb", :c => "c", :plain => "plain" }
|
||||
if !opts.doc?
|
||||
if !opts.present?(:doc)
|
||||
content = meth.source
|
||||
code_type = meth.source_type
|
||||
else
|
||||
|
@ -89,7 +89,7 @@ class Pry
|
|||
|
||||
link = Gist.write([:extension => ".#{type_map[code_type]}",
|
||||
:input => content],
|
||||
opts.p?)
|
||||
opts.present?(:private))
|
||||
|
||||
output.puts "Gist created at #{link}"
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
next if opts.h?
|
||||
next if opts.present?(:help)
|
||||
|
||||
if eval_string.empty?
|
||||
raise CommandError, "No input to amend."
|
||||
|
@ -78,16 +78,16 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
if opts.m?
|
||||
if opts.present?(:method)
|
||||
meth_name = opts[:m]
|
||||
meth = get_method_or_raise(meth_name, target, {}, :omit_help)
|
||||
next unless meth.source
|
||||
|
||||
range = opts.l? ? one_index_range_or_number(opts[:l]) : (0..-1)
|
||||
range = (0..-2) if opts.o?
|
||||
range = opts.present?(:lines) ? one_index_range_or_number(opts[:l]) : (0..-1)
|
||||
range = (0..-2) if opts.present?(:open)
|
||||
|
||||
eval_string << Array(meth.source.each_line.to_a[range]).join
|
||||
elsif opts.f?
|
||||
elsif opts.present?(:file)
|
||||
file_name = File.expand_path(opts[:f])
|
||||
|
||||
if !File.exists?(file_name)
|
||||
|
@ -95,8 +95,8 @@ class Pry
|
|||
end
|
||||
|
||||
text_array = File.readlines(file_name)
|
||||
range = opts.l? ? one_index_range_or_number(opts[:l]) : (0..-1)
|
||||
range = (0..-2) if opts.o?
|
||||
range = opts.present?(:lines) ? one_index_range_or_number(opts[:l]) : (0..-1)
|
||||
range = (0..-2) if opts.present?(:open)
|
||||
|
||||
_pry_.input_stack << _pry_.input
|
||||
_pry_.input = StringIO.new(Array(text_array[range]).join)
|
||||
|
@ -107,8 +107,8 @@ class Pry
|
|||
|
||||
code = target.eval(args.first)
|
||||
|
||||
range = opts.l? ? one_index_range_or_number(opts[:l]) : (0..-1)
|
||||
range = (0..-2) if opts.o?
|
||||
range = opts.present?(:lines) ? one_index_range_or_number(opts[:l]) : (0..-1)
|
||||
range = (0..-2) if opts.present?(:open)
|
||||
|
||||
eval_string << Array(code.each_line.to_a[range]).join
|
||||
end
|
||||
|
@ -153,15 +153,15 @@ class Pry
|
|||
output.puts opt.help
|
||||
end
|
||||
end
|
||||
next if opts.help?
|
||||
next if opts.present?(:help)
|
||||
|
||||
if opts.grep?
|
||||
if opts.present?(:grep)
|
||||
pattern = Regexp.new(arg_string.strip.split(/ /, 2).last.strip)
|
||||
history.pop
|
||||
|
||||
history.map!.with_index do |element, index|
|
||||
if element =~ pattern
|
||||
if opts.n?
|
||||
if opts.present?(:"no-numbers")
|
||||
element
|
||||
else
|
||||
"#{text.blue index}: #{element}"
|
||||
|
@ -173,11 +173,11 @@ class Pry
|
|||
next
|
||||
end
|
||||
|
||||
if opts.head?
|
||||
if opts.present?(:head)
|
||||
limit = opts['head'] || 10
|
||||
list = history.first limit
|
||||
lines = list.join("\n")
|
||||
if opts.n?
|
||||
if opts.present?(:"no-numbers")
|
||||
stagger_output lines
|
||||
else
|
||||
stagger_output text.with_line_numbers(lines, 0)
|
||||
|
@ -185,14 +185,14 @@ class Pry
|
|||
next
|
||||
end
|
||||
|
||||
if opts.tail?
|
||||
if opts.present?(:tail)
|
||||
limit = opts['tail'] || 10
|
||||
offset = history.size - limit
|
||||
offset = offset < 0 ? 0 : offset
|
||||
|
||||
list = history.last limit
|
||||
lines = list.join("\n")
|
||||
if opts.n?
|
||||
if opts.present?(:'no-numbers')
|
||||
stagger_output lines
|
||||
else
|
||||
stagger_output text.with_line_numbers(lines, offset)
|
||||
|
@ -200,11 +200,11 @@ class Pry
|
|||
next
|
||||
end
|
||||
|
||||
if opts.show?
|
||||
if opts.present?(:show)
|
||||
range = opts['show']
|
||||
start_line = range.is_a?(Range) ? range.first : range
|
||||
lines = Array(history[range]).join("\n")
|
||||
if opts.n?
|
||||
if opts.present?(:'no-numbers')
|
||||
stagger_output lines
|
||||
else
|
||||
stagger_output text.with_line_numbers(lines, start_line)
|
||||
|
@ -212,10 +212,10 @@ class Pry
|
|||
next
|
||||
end
|
||||
|
||||
if opts.exclude?
|
||||
if opts.present?(:exclude)
|
||||
history.map!.with_index do |element, index|
|
||||
unless command_processor.valid_command? element
|
||||
if opts.n?
|
||||
if opts.present?(:'no-numbers')
|
||||
element
|
||||
else
|
||||
"#{text.blue index}: #{element}"
|
||||
|
@ -226,7 +226,7 @@ class Pry
|
|||
next
|
||||
end
|
||||
|
||||
if opts.replay?
|
||||
if opts.present?(:replay)
|
||||
range = opts['replay']
|
||||
actions = Array(history[range]).join("\n") + "\n"
|
||||
_pry_.input_stack << _pry_.input
|
||||
|
@ -234,7 +234,7 @@ class Pry
|
|||
next
|
||||
end
|
||||
|
||||
if opts.clear?
|
||||
if opts.present?(:clear)
|
||||
Pry.history.clear
|
||||
output.puts 'History cleared.'
|
||||
next
|
||||
|
@ -274,7 +274,7 @@ class Pry
|
|||
end
|
||||
|
||||
lines = history.join("\n")
|
||||
if opts.n?
|
||||
if opts.present?(:'no-numbers')
|
||||
stagger_output lines
|
||||
else
|
||||
stagger_output text.with_line_numbers(lines, 0)
|
||||
|
|
|
@ -32,13 +32,13 @@ class Pry
|
|||
end
|
||||
|
||||
start_line = false
|
||||
if opts.b?
|
||||
if opts.present?(:'base-one')
|
||||
start_line = 1
|
||||
elsif opts.l?
|
||||
elsif opts.present?(:'line-numbers')
|
||||
start_line = meth.source_line || 1
|
||||
end
|
||||
|
||||
render_output(opts.flood?, start_line, code)
|
||||
render_output(opts.present?(:flood), start_line, code)
|
||||
end
|
||||
|
||||
alias_command "show-source", "show-method"
|
||||
|
@ -61,7 +61,7 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
next if opts.help?
|
||||
next if opts.present?(:help)
|
||||
|
||||
command_name = args.shift
|
||||
if !command_name
|
||||
|
@ -84,11 +84,11 @@ class Pry
|
|||
end
|
||||
|
||||
start_line = false
|
||||
if opts.l?
|
||||
if opts.present?(:'line-numbers')
|
||||
start_line = block.source_line || 1
|
||||
end
|
||||
|
||||
render_output(opts.flood?, opts.l? ? block.source_line : false, code)
|
||||
render_output(opts.present?(:flood), opts.present?(:'line-numbers') ? block.source_line : false, code)
|
||||
code
|
||||
else
|
||||
raise CommandError, "No such command: #{command_name}."
|
||||
|
@ -114,18 +114,18 @@ class Pry
|
|||
output.puts opt
|
||||
end
|
||||
end
|
||||
next if opts.h?
|
||||
next if opts.present?(:help)
|
||||
|
||||
if [opts.ex?, opts.t?, opts.i?, !args.empty?].count(true) > 1
|
||||
if [opts.present?(:ex), opts.present?(:temp), opts.present?(:in), !args.empty?].count(true) > 1
|
||||
raise CommandError, "Only one of --ex, --temp, --in and FILE may be specified."
|
||||
end
|
||||
|
||||
# edit of local code, eval'd within pry.
|
||||
if !opts.ex? && args.empty?
|
||||
if !opts.present?(:ex) && args.empty?
|
||||
|
||||
content = if opts.t?
|
||||
content = if opts.present?(:temp)
|
||||
""
|
||||
elsif opts.i?
|
||||
elsif opts.present?(:in)
|
||||
case opts[:i]
|
||||
when Range
|
||||
(_pry_.input_array[opts[:i]] || []).join
|
||||
|
@ -146,7 +146,7 @@ class Pry
|
|||
f.puts(content)
|
||||
f.flush
|
||||
invoke_editor(f.path, line)
|
||||
if !opts.n?
|
||||
if !opts.present?(:'no-reload')
|
||||
silence_warnings do
|
||||
eval_string.replace(File.read(f.path))
|
||||
end
|
||||
|
@ -155,7 +155,7 @@ class Pry
|
|||
|
||||
# edit of remote code, eval'd at top-level
|
||||
else
|
||||
if opts.ex?
|
||||
if opts.present?(:ex)
|
||||
if _pry_.last_exception.nil?
|
||||
raise CommandError, "No exception found."
|
||||
end
|
||||
|
@ -186,12 +186,12 @@ class Pry
|
|||
line = file_name.sub!(/:(\d+)$/, "") ? $1.to_i : 1
|
||||
end
|
||||
|
||||
line = opts[:l].to_i if opts.l?
|
||||
line = opts[:l].to_i if opts.present?(:line)
|
||||
|
||||
invoke_editor(file_name, line)
|
||||
set_file_and_dir_locals(file_name)
|
||||
|
||||
if opts.r? || ((opts.ex? || file_name.end_with?(".rb")) && !opts.n?)
|
||||
if opts.present?(:reload) || ((opts.present?(:ex) || file_name.end_with?(".rb")) && !opts.present?(:'no-reload'))
|
||||
silence_warnings do
|
||||
TOPLEVEL_BINDING.eval(File.read(file_name), file_name)
|
||||
end
|
||||
|
@ -222,7 +222,7 @@ class Pry
|
|||
raise CommandError, "No editor set!\nEnsure that #{text.bold("Pry.config.editor")} is set to your editor of choice."
|
||||
end
|
||||
|
||||
if opts.p? || meth.dynamically_defined?
|
||||
if opts.present?(:patch) || meth.dynamically_defined?
|
||||
lines = meth.source.lines.to_a
|
||||
|
||||
if ((original_name = meth.original_name) &&
|
||||
|
@ -256,7 +256,7 @@ class Pry
|
|||
|
||||
invoke_editor(file, opts["no-jump"] ? 0 : line)
|
||||
silence_warnings do
|
||||
load file if !opts.n? && !Pry.config.disable_auto_reload
|
||||
load file if !opts.present?(:'no-jump') && !Pry.config.disable_auto_reload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,11 +21,11 @@ class Pry
|
|||
|
||||
# Get all the methods that we'll want to output
|
||||
def all_methods(obj, opts)
|
||||
opts.M? ? Pry::Method.all_from_class(obj) : Pry::Method.all_from_obj(obj)
|
||||
opts.present?(:module) ? Pry::Method.all_from_class(obj) : Pry::Method.all_from_obj(obj)
|
||||
end
|
||||
|
||||
def resolution_order(obj, opts)
|
||||
opts.M? ? Pry::Method.instance_resolution_order(obj) : Pry::Method.resolution_order(obj)
|
||||
opts.present?(:module) ? Pry::Method.instance_resolution_order(obj) : Pry::Method.resolution_order(obj)
|
||||
end
|
||||
|
||||
# Get the name of the klass for pretty display in the title column of ls -m
|
||||
|
@ -48,9 +48,9 @@ class Pry
|
|||
# Get a lambda that can be used with .take_while to prevent over-eager
|
||||
# traversal of the Object's ancestry graph.
|
||||
def below_ceiling(obj, opts)
|
||||
ceiling = if opts.q?
|
||||
[opts.M? ? obj.ancestors[1] : obj.class.ancestors[1]] + Pry.config.ls.ceiling
|
||||
elsif opts.v?
|
||||
ceiling = if opts.present?(:quiet)
|
||||
[opts.present?(:module) ? obj.ancestors[1] : obj.class.ancestors[1]] + Pry.config.ls.ceiling
|
||||
elsif opts.present?(:verbose)
|
||||
[]
|
||||
else
|
||||
Pry.config.ls.ceiling.dup
|
||||
|
@ -160,41 +160,43 @@ class Pry
|
|||
opt.on :h, "help", "Show help"
|
||||
end
|
||||
|
||||
next output.puts(opts) if opts.h?
|
||||
next output.puts(opts) if opts.present?(:help)
|
||||
|
||||
obj = args.empty? ? target_self : target.eval(args.join(" "))
|
||||
|
||||
# exclude -q, -v and --grep because they don't specify what the user wants to see.
|
||||
has_opts = (opts.m? || opts.M? || opts.p? || opts.g? || opts.l? || opts.c? || opts.i?)
|
||||
has_opts = (opts.present?(:methods) || opts.present?(:module) || opts.present?(:ppp) ||
|
||||
opts.present?(:globals) || opts.present?(:locals) || opts.present?(:constants) ||
|
||||
opts.present?(:ivars))
|
||||
|
||||
show_methods = opts.m? || opts.M? || opts.p? || !has_opts
|
||||
show_constants = opts.c? || (!has_opts && Module === obj)
|
||||
show_ivars = opts.i? || !has_opts
|
||||
show_locals = opts.l? || (!has_opts && args.empty?)
|
||||
show_methods = opts.present?(:methods) || opts.present?(:module) || opts.present?(:ppp) || !has_opts
|
||||
show_constants = opts.present?(:constants) || (!has_opts && Module === obj)
|
||||
show_ivars = opts.present?(:ivars) || !has_opts
|
||||
show_locals = opts.present?(:locals) || (!has_opts && args.empty?)
|
||||
|
||||
grep_regex, grep = [Regexp.new(opts[:G] || "."), lambda{ |x| x.grep(grep_regex) }]
|
||||
|
||||
raise Pry::CommandError, "-l does not make sense with a specified Object" if opts.l? && !args.empty?
|
||||
raise Pry::CommandError, "-g does not make sense with a specified Object" if opts.g? && !args.empty?
|
||||
raise Pry::CommandError, "-q does not make sense with -v" if opts.q? && opts.v?
|
||||
raise Pry::CommandError, "-M only makes sense with a Module or a Class" if opts.M? && !(Module === obj)
|
||||
raise Pry::CommandError, "-c only makes sense with a Module or a Class" if opts.c? && !args.empty? && !(Module === obj)
|
||||
raise Pry::CommandError, "-l does not make sense with a specified Object" if opts.present?(:locals) && !args.empty?
|
||||
raise Pry::CommandError, "-g does not make sense with a specified Object" if opts.present?(:globals) && !args.empty?
|
||||
raise Pry::CommandError, "-q does not make sense with -v" if opts.present?(:quiet) && opts.present?(:verbose)
|
||||
raise Pry::CommandError, "-M only makes sense with a Module or a Class" if opts.present?(:module) && !(Module === obj)
|
||||
raise Pry::CommandError, "-c only makes sense with a Module or a Class" if opts.present?(:constants) && !args.empty? && !(Module === obj)
|
||||
|
||||
|
||||
if opts.g?
|
||||
if opts.present?(:globals)
|
||||
output_section("global variables", grep[format_globals(target.eval("global_variables"))])
|
||||
end
|
||||
|
||||
if show_constants
|
||||
mod = Module === obj ? obj : Object
|
||||
constants = mod.constants
|
||||
constants -= (mod.ancestors - [mod]).map(&:constants).flatten unless opts.v?
|
||||
constants -= (mod.ancestors - [mod]).map(&:constants).flatten unless opts.present?(:verbose)
|
||||
output_section("constants", grep[format_constants(mod, constants)])
|
||||
end
|
||||
|
||||
if show_methods
|
||||
# methods is a hash {Module/Class => [Pry::Methods]}
|
||||
methods = all_methods(obj, opts).select{ |method| opts.p? || method.visibility == :public }.group_by(&:owner)
|
||||
methods = all_methods(obj, opts).select{ |method| opts.present?(:ppp) || method.visibility == :public }.group_by(&:owner)
|
||||
|
||||
# reverse the resolution order so that the most useful information appears right by the prompt
|
||||
resolution_order(obj, opts).take_while(&below_ceiling(obj, opts)).reverse.each do |klass|
|
||||
|
|
|
@ -78,9 +78,9 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
next if opts.help?
|
||||
next if opts.present?(:help)
|
||||
|
||||
if opts.ex?
|
||||
if opts.present?(:ex)
|
||||
if file_name.nil?
|
||||
raise CommandError, "No Exception or Exception has no associated file."
|
||||
end
|
||||
|
@ -88,7 +88,7 @@ class Pry
|
|||
file_name = args.shift
|
||||
end
|
||||
|
||||
if opts.i?
|
||||
if opts.present?(:in)
|
||||
normalized_range = absolute_index_range(opts[:i], _pry_.input_array.length)
|
||||
input_items = _pry_.input_array[normalized_range] || []
|
||||
|
||||
|
@ -106,7 +106,7 @@ class Pry
|
|||
|
||||
code = syntax_highlight_by_file_type_or_specified(s, nil, :ruby)
|
||||
|
||||
if opts.l?
|
||||
if opts.present?(:'line-numbers')
|
||||
contents << text.indent(text.with_line_numbers(code, 1), 2)
|
||||
else
|
||||
contents << text.indent(code, 2)
|
||||
|
@ -128,13 +128,13 @@ class Pry
|
|||
|
||||
contents = syntax_highlight_by_file_type_or_specified(contents, file_name, opts[:type])
|
||||
|
||||
if opts.l?
|
||||
if opts.present?(:'line-numbers')
|
||||
contents = text.with_line_numbers contents, start_line + 1
|
||||
end
|
||||
end
|
||||
|
||||
# add the arrow pointing to line that caused the exception
|
||||
if opts.ex?
|
||||
if opts.present?(:ex)
|
||||
ex_file, ex_line = _pry_.last_exception.bt_source_location_for(bt_index)
|
||||
contents = text.with_line_numbers contents, start_line + 1, :bright_red
|
||||
|
||||
|
@ -154,7 +154,7 @@ class Pry
|
|||
|
||||
set_file_and_dir_locals(file_name)
|
||||
|
||||
if opts.f?
|
||||
if opts.present?(:flood)
|
||||
output.puts contents
|
||||
else
|
||||
stagger_output(contents)
|
||||
|
|
|
@ -47,9 +47,9 @@ class Pry
|
|||
|
||||
# Add the derived :method_object option to a used Slop instance.
|
||||
def process_method_object_options(args, opts)
|
||||
opts[:instance] = opts['instance-methods'] if opts.m?
|
||||
opts[:instance] = opts['instance-methods'] if opts.present?(:methods)
|
||||
# TODO: de-hack when we upgrade Slop: https://github.com/injekt/slop/pull/30
|
||||
opts.options[:super].force_argument_value opts.options[:super].count if opts.super?
|
||||
opts.options[:super].force_argument_value opts.options[:super].count if opts.present?(:super)
|
||||
|
||||
get_method_or_raise(args.empty? ? nil : args.join(" "), @method_target, opts.to_hash(true))
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue