cmd/search: fix filtering of aliases in results

By directly modifying the results array with
`results[i] = "#{name} (installed)"`, it appeared on successive
iterations that the canonical name was no longer in the array, so
aliases were not removed.

See 9efe5b554c (commitcomment-12969631)

Closes Homebrew/homebrew#43433.
This commit is contained in:
Alex Dunn 2015-08-31 00:23:30 -07:00
parent 5dd0f089a3
commit 79ea14b738

View File

@ -143,15 +143,16 @@ module Homebrew
aliases = Formula.aliases aliases = Formula.aliases
results = (Formula.full_names+aliases).grep(rx).sort results = (Formula.full_names+aliases).grep(rx).sort
results.each_with_index do |name, i| results.map do |name|
canonical_name = Formulary.canonical_name(name) canonical_name = Formulary.canonical_name(name)
# Remove aliases from results when the full name was also found # Ignore aliases from results when the full name was also found
if aliases.include?(name) && results.include?(canonical_name) if aliases.include?(name) && results.include?(canonical_name)
results.delete_at(i) next
# Notify the user if the formula is installed
elsif (HOMEBREW_CELLAR/canonical_name).directory? elsif (HOMEBREW_CELLAR/canonical_name).directory?
results[i] = "#{name} (installed)" "#{name} (installed)"
else
name
end end
end end.compact
end end
end end