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

got CommandBase working; just need to migrate old commands into a new commands.rb and move CommandBase into command_base.rb

This commit is contained in:
John Mair 2011-01-11 13:14:25 +11:00
parent a832451e9e
commit 8e006829fe
2 changed files with 25 additions and 10 deletions

View file

@ -10,7 +10,6 @@ class Pry
@commands = {}
@command_info = {}
class Command
Elements = [:name, :description, :pattern, :action]
@ -32,9 +31,8 @@ class Pry
def self.command(name, &block)
c = Command.new
c.name name
# c.instance_eval(&block)
c.instance_eval(&block)
c.instance_eval(&block)
check_command(c)
commands.merge! c.get_pattern => c.get_action
@ -42,21 +40,37 @@ class Pry
end
command "help" do
pattern /^help\s*(.+)?/
description "This menu."
action proc { |opts|
out = opts[:output]
command_info = opts[:command_info]
param = opts[:captures].first
puts opts[:captures].inspect
if !param
out.puts "Command list:"
out.puts "--"
opts[:command_info].each do |k, v|
command_info.each do |k, v|
puts "#{Array(k).first}".ljust(18) + v
end
else
key = command_info.keys.find { |v| Array(v).any? { |k| k === param } }
if key
out.puts command_info[key]
else
out.puts "No info for command: #{param}"
end
end
opts[:val].clear
}
end
end
# Default commands used by Pry.
# @note
# If you plan to replace the default Commands class with a custom

View file

@ -179,7 +179,8 @@ class Pry
:target => target,
:val => val,
:nesting => nesting,
:output => output
:output => output,
:command_info => commands.command_info
}
action.call(options)