made it so aliases are now added as separate commands, no longer an array of commands - makes it easier to override aliased commands in subclasses

This commit is contained in:
John Mair 2011-01-20 14:58:30 +13:00
parent 8394004c93
commit ec66e9bade
2 changed files with 7 additions and 6 deletions

View File

@ -40,16 +40,17 @@ class Pry
arg_match = '(?:\s+(\S+))?' * 20 arg_match = '(?:\s+(\S+))?' * 20
if name.is_a?(Array) if name.is_a?(Array)
matcher = []
name.each do |n| name.each do |n|
matcher << /^#{n}(?!\S)#{arg_match}?/ matcher = /^#{n}(?!\S)#{arg_match}?/
commands[matcher] = block
command_info[n] = description
end end
else else
matcher = /^#{name}(?!\S)#{arg_match}?/ matcher = /^#{name}(?!\S)#{arg_match}?/
commands[matcher] = block
command_info[name] = description
end end
commands[matcher] = block
command_info[name] = description
end end
end end
command "help", "This menu." do |cmd| command "help", "This menu." do |cmd|
@ -61,7 +62,7 @@ class Pry
out.puts "Command list:" out.puts "Command list:"
out.puts "--" out.puts "--"
command_info.each do |k, v| command_info.each do |k, v|
out.puts "#{Array(k).first}".ljust(18) + v out.puts "#{k}".ljust(18) + v
end end
else else
key = command_info.keys.find { |v| Array(v).any? { |k| k === param } } key = command_info.keys.find { |v| Array(v).any? { |k| k === param } }

View File

@ -182,7 +182,7 @@ class Pry
def val.clear() replace("") end def val.clear() replace("") end
def eval_string.clear() replace("") end def eval_string.clear() replace("") end
pattern, action = commands.commands.find { |k, v| Array(k).any? { |a| a === val } } pattern, action = commands.commands.find { |k, v| k === val }
if pattern if pattern
captures = Regexp.last_match.captures captures = Regexp.last_match.captures