Fix search_tap regex/string matching.
This commit is contained in:
parent
50b635e276
commit
f732278cda
@ -40,8 +40,8 @@ module Homebrew
|
|||||||
exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all§ion=all"
|
exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all§ion=all"
|
||||||
elsif ARGV.include? "--desc"
|
elsif ARGV.include? "--desc"
|
||||||
query = ARGV.next
|
query = ARGV.next
|
||||||
rx = query_regexp(query)
|
regex = query_regexp(query)
|
||||||
Descriptions.search(rx, :desc).print
|
Descriptions.search(regex, :desc).print
|
||||||
elsif ARGV.first =~ HOMEBREW_TAP_FORMULA_REGEX
|
elsif ARGV.first =~ HOMEBREW_TAP_FORMULA_REGEX
|
||||||
query = ARGV.first
|
query = ARGV.first
|
||||||
user, repo, name = query.split("/", 3)
|
user, repo, name = query.split("/", 3)
|
||||||
@ -55,10 +55,10 @@ module Homebrew
|
|||||||
puts_columns Array(result)
|
puts_columns Array(result)
|
||||||
else
|
else
|
||||||
query = ARGV.first
|
query = ARGV.first
|
||||||
rx = query_regexp(query)
|
regex = query_regexp(query)
|
||||||
local_results = search_formulae(rx)
|
local_results = search_formulae(regex)
|
||||||
puts_columns(local_results)
|
puts_columns(local_results)
|
||||||
tap_results = search_taps(rx)
|
tap_results = search_taps(regex)
|
||||||
puts_columns(tap_results)
|
puts_columns(tap_results)
|
||||||
|
|
||||||
if $stdout.tty?
|
if $stdout.tty?
|
||||||
@ -112,15 +112,17 @@ module Homebrew
|
|||||||
odie "#{query} is not a valid regex"
|
odie "#{query} is not a valid regex"
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_taps(rx)
|
def search_taps(regex_or_string)
|
||||||
SEARCHABLE_TAPS.map do |user, repo|
|
SEARCHABLE_TAPS.map do |user, repo|
|
||||||
Thread.new { search_tap(user, repo, rx) }
|
Thread.new { search_tap(user, repo, regex_or_string) }
|
||||||
end.inject([]) do |results, t|
|
end.inject([]) do |results, t|
|
||||||
results.concat(t.value)
|
results.concat(t.value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_tap(user, repo, rx)
|
def search_tap(user, repo, regex_or_string)
|
||||||
|
regex = regex_or_string.is_a?(String) ? /^#{Regexp.escape(regex_or_string)}$/ : regex_or_string
|
||||||
|
|
||||||
if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}/homebrew-#{repo.downcase}").directory? && \
|
if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}/homebrew-#{repo.downcase}").directory? && \
|
||||||
user != "Caskroom"
|
user != "Caskroom"
|
||||||
return []
|
return []
|
||||||
@ -150,7 +152,7 @@ module Homebrew
|
|||||||
|
|
||||||
names = remote_tap_formulae["#{user}/#{repo}"]
|
names = remote_tap_formulae["#{user}/#{repo}"]
|
||||||
user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization
|
user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization
|
||||||
names.select { |name| name =~ rx }.map { |name| "#{user}/#{repo}/#{name}" }
|
names.select { |name| name =~ regex }.map { |name| "#{user}/#{repo}/#{name}" }
|
||||||
rescue GitHub::HTTPNotFoundError
|
rescue GitHub::HTTPNotFoundError
|
||||||
opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
|
opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
|
||||||
[]
|
[]
|
||||||
@ -159,9 +161,9 @@ module Homebrew
|
|||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_formulae(rx)
|
def search_formulae(regex)
|
||||||
aliases = Formula.alias_full_names
|
aliases = Formula.alias_full_names
|
||||||
results = (Formula.full_names+aliases).grep(rx).sort
|
results = (Formula.full_names+aliases).grep(regex).sort
|
||||||
|
|
||||||
results.map do |name|
|
results.map do |name|
|
||||||
begin
|
begin
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user