Add deprecated_commands API

And rewrite edit-method / show-command to use this API.
This commit is contained in:
John Mair 2013-01-15 21:48:16 +01:00
parent b6b78157a5
commit 0531b8a7bd
5 changed files with 14 additions and 60 deletions

View File

@ -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.

View File

@ -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)

View 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.")

View File

@ -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

View File

@ -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