mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
DRYify CommandSet#find_command_by_match_or_listing
Also, refactor `BaseHelpers#find_command` again, so we can choose where we we want to find our `name`. Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
This commit is contained in:
parent
af1a6e98c7
commit
0241d230c5
2 changed files with 5 additions and 10 deletions
|
@ -196,14 +196,9 @@ class Pry
|
|||
# of the command to retrieve.
|
||||
# @return [Command] The command object matched.
|
||||
def find_command_by_match_or_listing(match_or_listing)
|
||||
if commands[match_or_listing]
|
||||
cmd = commands[match_or_listing]
|
||||
else
|
||||
_, cmd = commands.find { |match, command| command.options[:listing] == match_or_listing }
|
||||
end
|
||||
|
||||
raise ArgumentError, "Cannot find a command: '#{match_or_listing}'!" if !cmd
|
||||
cmd
|
||||
cmd = (commands[match_or_listing] ||
|
||||
Pry::Helpers::BaseHelpers.find_command(match_or_listing, commands))
|
||||
cmd or raise ArgumentError, "Cannot find a command: '#{match_or_listing}'!"
|
||||
end
|
||||
|
||||
# Aliases a command
|
||||
|
|
|
@ -24,8 +24,8 @@ class Pry
|
|||
end
|
||||
public :safe_send
|
||||
|
||||
def find_command(name)
|
||||
command_match = Pry::Commands.find do |_, command|
|
||||
def find_command(name, set = Pry::Commands)
|
||||
command_match = set.find do |_, command|
|
||||
command.options[:listing] == name
|
||||
end
|
||||
command_match.last if command_match
|
||||
|
|
Loading…
Add table
Reference in a new issue