mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Add deprecated_commands API
And rewrite edit-method / show-command to use this API.
This commit is contained in:
parent
b6b78157a5
commit
0531b8a7bd
5 changed files with 14 additions and 60 deletions
|
@ -263,6 +263,17 @@ class Pry
|
|||
commands.delete(cmd.match)
|
||||
end
|
||||
|
||||
def deprecated_command(name_of_deprecated_command, deprecation_message, matcher=name_of_deprecated_command)
|
||||
create_command name_of_deprecated_command do
|
||||
match matcher
|
||||
description ""
|
||||
|
||||
define_method(:process) do
|
||||
output.puts "DEPRECATED: #{deprecation_message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Sets or gets the description for a command (replacing the old
|
||||
# description). Returns current description if no description
|
||||
# parameter provided.
|
||||
|
|
|
@ -103,7 +103,7 @@ class Pry
|
|||
pry_array_content_as_string(_pry_.input_array, self.class.input_expression_ranges) { |v| v }
|
||||
end
|
||||
|
||||
# The line range passed to `--lines`
|
||||
# The line range passed to `--lines`, converted to a 0-indexed range.
|
||||
def line_range
|
||||
opts.present?(:lines) ? one_index_range_or_number(opts[:lines]) : 0..-1
|
||||
end
|
||||
|
@ -144,7 +144,6 @@ class Pry
|
|||
if File.exists?(obj_name)
|
||||
# Set the file accessor.
|
||||
self.file = obj_name
|
||||
|
||||
File.read(obj_name)
|
||||
else
|
||||
could_not_locate(obj_name)
|
||||
|
|
2
lib/pry/commands/deprecated_commands.rb
Normal file
2
lib/pry/commands/deprecated_commands.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
Pry::Commands.deprecated_command("edit-method", "Use `edit` instead.")
|
||||
Pry::Commands.deprecated_command("show-command", "Use show-source [command_name] instead.")
|
|
@ -1,29 +0,0 @@
|
|||
class Pry
|
||||
class Command::EditMethod < Pry::ClassCommand
|
||||
match 'edit-method'
|
||||
group 'Editing'
|
||||
description 'Show the source for CMD.'
|
||||
|
||||
banner <<-'BANNER'
|
||||
Show the source for CMD.
|
||||
BANNER
|
||||
|
||||
def process(*args)
|
||||
target = target()
|
||||
|
||||
opts = Slop.parse!(args) do |opt|
|
||||
opt.banner unindent <<-'BANNER'
|
||||
NOTE: edit-method is DEPRECATED. Use `edit` instead.
|
||||
BANNER
|
||||
|
||||
opt.on :h, :help, "This message" do
|
||||
output.puts opt.help
|
||||
end
|
||||
end
|
||||
|
||||
stagger_output opts.banner
|
||||
end
|
||||
end
|
||||
|
||||
Pry::Commands.add_command(Pry::Command::EditMethod)
|
||||
end
|
|
@ -1,29 +0,0 @@
|
|||
class Pry
|
||||
class Command::ShowCommand < Pry::ClassCommand
|
||||
match 'show-command'
|
||||
group 'Introspection'
|
||||
description 'Show the source for CMD.'
|
||||
|
||||
banner <<-'BANNER'
|
||||
Show the source for CMD.
|
||||
BANNER
|
||||
|
||||
def process(*args)
|
||||
target = target()
|
||||
|
||||
opts = Slop.parse!(args) do |opt|
|
||||
opt.banner unindent <<-'BANNER'
|
||||
NOTE: show-command is DEPRECATED. Use show-source [command_name] instead.
|
||||
BANNER
|
||||
|
||||
opt.on :h, :help, "This message" do
|
||||
output.puts opt.help
|
||||
end
|
||||
end
|
||||
|
||||
render_output opts.banner
|
||||
end
|
||||
end
|
||||
|
||||
Pry::Commands.add_command(Pry::Command::ShowCommand)
|
||||
end
|
Loading…
Add table
Reference in a new issue