1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Quash (most) warnings emitted by -w.

Two remain:

- two from method_source gem.
This commit is contained in:
Rob Gleeson 2011-05-19 16:53:44 +01:00
parent 1409d162c6
commit 7051c12730
10 changed files with 123 additions and 131 deletions

View file

@ -90,7 +90,7 @@ class Pry
# @param [String] val The line of input.
# @return [Array] The command data and arg string pair
def command_matched(val)
_, cmd_data = commands.commands.find do |name, cmd_data|
_, cmd_data = commands.commands.find do |name, data|
/^#{Regexp.escape(name)}(?!\S)(?:\s+(.+))?/ =~ val
end

View file

@ -26,7 +26,7 @@ class Pry
args
when 1, 0
# Keep 1.8 happy
args.values_at *0..(arity - 1)
args.values_at 0..(arity - 1)
end
end
end

View file

@ -10,20 +10,19 @@ class Pry
command "show-doc", "Show the comments above METH. Type `show-doc --help` for more info. Aliases: \?" do |*args|
target = target()
opts = Slop.parse!(args) do |opts|
opts.banner %{Usage: show-doc [OPTIONS] [METH]
Show the comments above method METH. Tries instance methods first and then methods by default.
e.g show-doc hello_method
--
}
opts.on :M, "instance-methods", "Operate on instance methods."
opts.on :m, :methods, "Operate on methods."
opts.on :c, :context, "Select object context to run under.", true do |context|
opts = Slop.parse!(args) do |opt|
opt.banner = "Usage: show-doc [OPTIONS] [METH]\n" \
"Show the comments above method METH. Tries instance methods first and then methods by default.\n" \
"e.g show-doc hello_method"
opt.on :M, "instance-methods", "Operate on instance methods."
opt.on :m, :methods, "Operate on methods."
opt.on :c, :context, "Select object context to run under.", true do |context|
target = Pry.binding_for(target.eval(context))
end
opts.on :f, :flood, "Do not use a pager to view text longer than one screen."
opts.on :h, :help, "This message." do
output.puts opts
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
opt.on :h, :help, "This message." do
output.puts opt
end
end
@ -51,19 +50,18 @@ e.g show-doc hello_method
command "stat", "View method information and set _file_ and _dir_ locals. Type `stat --help` for more info." do |*args|
target = target()
opts = Slop.parse!(args) do |opts|
opts.banner %{Usage: stat [OPTIONS] [METH]
Show method information for method METH and set _file_ and _dir_ locals.
e.g: stat hello_method
--
}
opts.on :M, "instance-methods", "Operate on instance methods."
opts.on :m, :methods, "Operate on methods."
opts.on :c, :context, "Select object context to run under.", true do |context|
opts = Slop.parse!(args) do |opt|
opt.banner "Usage: stat [OPTIONS] [METH]\n" \
"Show method information for method METH and set _file_ and _dir_ locals." \
"e.g: stat hello_method"
opt.on :M, "instance-methods", "Operate on instance methods."
opt.on :m, :methods, "Operate on methods."
opt.on :c, :context, "Select object context to run under.", true do |context|
target = Pry.binding_for(target.eval(context))
end
opts.on :h, :help, "This message" do
output.puts opts
opt.on :h, :help, "This message" do
output.puts opt
end
end
@ -99,19 +97,18 @@ e.g: stat hello_method
target = target()
opts = Slop.parse!(args) do |opts|
opts.banner = %{Usage: gist-method [OPTIONS] [METH]
Gist the method (doc or source) to github.
Ensure the `gist` gem is properly working before use. http://github.com/defunkt/gist for instructions.
e.g: gist -m my_method
e.g: gist -d my_method
--
}
opts.on :m, :method, "Gist a method's source."
opts.on :d, :doc, "Gist a method's documentation."
opts.on :p, :private, "Create a private gist (default: true)", :default => true
opts.on :h, :help, "This message" do
output.puts opts
opts = Slop.parse!(args) do |opt|
opt.banner "Usage: gist-method [OPTIONS] [METH]\n" \
"Gist the method (doc or source) to github.\n" \
"Ensure the `gist` gem is properly working before use. http://github.com/defunkt/gist for instructions.\n" \
"e.g: gist -m my_method\n" \
"e.g: gist -d my_method\n"
opt.on :m, :method, "Gist a method's source."
opt.on :d, :doc, "Gist a method's documentation."
opt.on :p, :private, "Create a private gist (default: true)", :default => true
opt.on :h, :help, "This message" do
output.puts opt
end
end

View file

@ -6,21 +6,20 @@ class Pry
command "show-method", "Show the source for METH. Type `show-method --help` for more info. Aliases: $, show-source" do |*args|
target = target()
opts = Slop.parse!(args) do |opts|
opts.banner %{Usage: show-method [OPTIONS] [METH]
Show the source for method METH. Tries instance methods first and then methods by default.
e.g: show-method hello_method
--
}
opts.on :l, "line-numbers", "Show line numbers."
opts.on :M, "instance-methods", "Operate on instance methods."
opts.on :m, :methods, "Operate on methods."
opts.on :f, :flood, "Do not use a pager to view text longer than one screen."
opts.on :c, :context, "Select object context to run under.", true do |context|
opts = Slop.parse!(args) do |opt|
opt.banner "Usage: show-method [OPTIONS] [METH]\n" \
"Show the source for method METH. Tries instance methods first and then methods by default.\n" \
"e.g: show-method hello_method"
opt.on :l, "line-numbers", "Show line numbers."
opt.on :M, "instance-methods", "Operate on instance methods."
opt.on :m, :methods, "Operate on methods."
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
opt.on :c, :context, "Select object context to run under.", true do |context|
target = Pry.binding_for(target.eval(context))
end
opts.on :h, :help, "This message." do
output.puts opts
opt.on :h, :help, "This message." do
output.puts opt
end
end
@ -55,16 +54,15 @@ e.g: show-method hello_method
command "show-command", "Show the source for CMD. Type `show-command --help` for more info." do |*args|
target = target()
opts = Slop.parse!(args) do |opts|
opts.banner = %{Usage: show-command [OPTIONS] [CMD]
Show the source for command CMD.
e.g: show-command show-method
--
}
opts.on :l, "line-numbers", "Show line numbers."
opts.on :f, :flood, "Do not use a pager to view text longer than one screen."
opts.on :h, :help, "This message." do
output.puts opts
opts = Slop.parse!(args) do |opt|
opt.banner = "Usage: show-command [OPTIONS] [CMD]\n" \
"Show the source for command CMD.\n" \
"e.g: show-command show-method"
opt.on :l, "line-numbers", "Show line numbers."
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
opt.on :h, :help, "This message." do
output.puts opt
end
end
@ -100,22 +98,21 @@ e.g: show-command show-method
command "edit-method", "Edit a method. Type `edit-method --help` for more info." do |*args|
target = target()
opts = Slop.parse!(args) do |opts|
opts.banner %{Usage: edit-method [OPTIONS] [METH]
Edit the method METH in an editor.
Ensure #{text.bold("Pry.editor")} is set to your editor of choice.
e.g: edit-method hello_method
--
}
opts.on :M, "instance-methods", "Operate on instance methods."
opts.on :m, :methods, "Operate on methods."
opts.on "no-reload", "Do not automatically reload the method's file after editting."
opts.on :n, "no-jump", "Do not fast forward editor to first line of method."
opts.on :c, :context, "Select object context to run under.", true do |context|
opts = Slop.parse!(args) do |opt|
opt.banner "Usage: edit-method [OPTIONS] [METH]\n" \
"Edit the method METH in an editor.\n" \
"Ensure #{text.bold("Pry.editor")} is set to your editor of choice.\n" \
"e.g: edit-method hello_method"
opt.on :M, "instance-methods", "Operate on instance methods."
opt.on :m, :methods, "Operate on methods."
opt.on "no-reload", "Do not automatically reload the method's file after editting."
opt.on :n, "no-jump", "Do not fast forward editor to first line of method."
opt.on :c, :context, "Select object context to run under.", true do |context|
target = Pry.binding_for(target.eval(context))
end
opts.on :h, :help, "This message." do
output.puts opts
opt.on :h, :help, "This message." do
output.puts opt
end
end

View file

@ -194,6 +194,6 @@ Shows local and instance variables by default.
end
end
end
end
end

View file

@ -27,20 +27,20 @@ class Pry
start_line = 0
end_line = -1
opts = Slop.parse!(args) do |opts|
opts.on :s, :start, "Start line (defaults to start of file)Line 1 is the first line.", true, :as => Integer do |line|
opts = Slop.parse!(args) do |opt|
opt.on :s, :start, "Start line (defaults to start of file)Line 1 is the first line.", true, :as => Integer do |line|
start_line = line - 1
end
opts.on :e, :end, "End line (defaults to end of file). Line -1 is the last line", true, :as => Integer do |line|
opt.on :e, :end, "End line (defaults to end of file). Line -1 is the last line", true, :as => Integer do |line|
end_line = line - 1
end
opts.on :l, "line-numbers", "Show line numbers."
opts.on :t, :type, "The specific file type for syntax higlighting (e.g ruby, python)", true, :as => Symbol
opts.on :f, :flood, "Do not use a pager to view text longer than one screen."
opts.on :h, :help, "This message." do
output.puts opts
opt.on :l, "line-numbers", "Show line numbers."
opt.on :t, :type, "The specific file type for syntax higlighting (e.g ruby, python)", true, :as => Symbol
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
opt.on :h, :help, "This message." do
output.puts opt
end
end

View file

@ -17,7 +17,7 @@ class Pry
command "play-method", "Play a method source as input" do |*args|
target = target()
opt = Slop.parse!(args) do |opt|
opts = Slop.parse!(args) do |opt|
opt.banner "Usage: play-method [--replay START..END] [--clear] [--grep PATTERN] [--help]\n"
opt.on :l, :lines, 'The line (or range of lines) to replay.', true, :as => Range
@ -26,7 +26,7 @@ class Pry
end
end
next if opt.help?
next if opts.help?
meth_name = args.shift
if (meth = get_method_object(meth_name, target, {})).nil?
@ -37,7 +37,7 @@ class Pry
code, code_type = code_and_code_type_for(meth)
next if !code
slice = opt[:l] ? opt[:l] : (0..-1)
slice = opts[:l] ? opts[:l] : (0..-1)
sliced_code = code.each_line.to_a[slice].join("\n")

View file

@ -41,12 +41,6 @@ class Pry
!!(file =~ /(\(.*\))|<.*>/)
end
def check_for_dynamically_defined_method(meth)
if is_a_dynamically_defined_method?(meth)
raise "Cannot retrieve source for dynamically defined method."
end
end
def check_for_dynamically_defined_method(meth)
file, _ = meth.source_location
if file =~ /(\(.*\))|<.*>/
@ -262,7 +256,7 @@ class Pry
end
def strip_comments_from_c_code(code)
code.sub /\A\s*\/\*.*?\*\/\s*/m, ''
code.sub(/\A\s*\/\*.*?\*\/\s*/m, '')
end
def prompt(message, options="Yn")

View file

@ -38,7 +38,7 @@ class Pry
# @param [String, #to_s] text
# @return [String] _text_ stripped of any color codes.
def strip_color text
text.to_s.gsub /\e\[.*?(\d)+m/, ''
text.to_s.gsub(/\e\[.*?(\d)+m/ , '')
end
# Returns _text_ as bold text for use on a terminal.

View file

@ -1,13 +1,15 @@
require "pry/command_processor.rb"
# @attr prompt
class Pry
# The list of configuration options.
CONFIG_OPTIONS = [:input, :output, :commands, :print,
:exception_handler, :prompt, :hooks,
:custom_completions]
attr_accessor *CONFIG_OPTIONS
attr_accessor :input
attr_accessor :output
attr_accessor :commands
attr_accessor :print
attr_accessor :exception_handler
attr_accessor :hooks
attr_accessor :custom_completions
# Returns the target binding for the session. Note that altering this
# attribute will not change the target binding.
@ -24,18 +26,44 @@ class Pry
# @option options [Proc] :print The Proc to use for the 'print'
# component of the REPL. (see print.rb)
def initialize(options={})
defaults = {}
attributes = [
:input, :output, :commands, :print,
:exception_handler, :hooks, :custom_completions,
:prompt
]
default_options = {}
CONFIG_OPTIONS.each { |v| default_options[v] = Pry.send(v) }
default_options.merge!(options)
CONFIG_OPTIONS.each do |key|
send "#{key}=", default_options[key]
attributes.each do |attribute|
defaults[attribute] = Pry.send attribute
end
defaults.merge!(options).each_key do |key|
send "#{key}=", defaults[key]
end
@command_processor = CommandProcessor.new(self)
end
# The current prompt.
# This is the prompt at the top of the prompt stack.
#
# @example
# self.prompt = Pry::SIMPLE_PROMPT
# self.prompt # => Pry::SIMPLE_PROMPT
#
# @return [Array<Proc>] Current prompt.
def prompt
prompt_stack.last
end
def prompt=(new_prompt)
if prompt_stack.empty?
push_prompt new_prompt
else
prompt_stack[-1] = new_prompt
end
end
# Get nesting data.
# This method should not need to be accessed directly.
# @return [Array] The unparsed nesting information.
@ -326,30 +354,6 @@ class Pry
end
private :prompt_stack
# The current prompt, this is the prompt at the top of the prompt stack.
# @return [Array<Proc>] Current prompt.
# @example
# push_prompt(Pry::SIMPLE_PROMPT)
# prompt # => Pry::SIMPLE_PROMPT
def prompt
prompt_stack.last
end
# Replaces the current prompt with the new prompt.
# Does not change the rest of the prompt stack.
# @param [Array<Proc>] new_prompt
# @return [Array<Proc>] new_prompt
# @example
# pry.prompt = Pry::SIMPLE_PROMPT # => Pry::SIMPLE_PROMPT
# pry.prompt # => Pry::SIMPLE_PROMPT
def prompt=(new_prompt)
if prompt_stack.empty?
push_prompt new_prompt
else
prompt_stack[-1] = new_prompt
end
end
# Pushes the current prompt onto a stack that it can be restored from later.
# Use this if you wish to temporarily change the prompt.
# @param [Array<Proc>] new_prompt