2013-06-11 22:23:19 -05:00
|
|
|
require 'formula'
|
|
|
|
require 'blacklist'
|
|
|
|
require 'utils'
|
2013-06-22 16:51:08 -05:00
|
|
|
require 'utils/json'
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def search
|
|
|
|
if ARGV.include? '--macports'
|
2012-12-27 23:34:29 -06:00
|
|
|
exec_browser "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
|
2010-09-11 20:22:54 +01:00
|
|
|
elsif ARGV.include? '--fink'
|
2012-12-27 23:34:29 -06:00
|
|
|
exec_browser "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}"
|
2013-05-27 17:30:45 -07:00
|
|
|
elsif ARGV.include? '--debian'
|
|
|
|
exec_browser "http://packages.debian.org/search?keywords=#{ARGV.next}&searchon=names&suite=all§ion=all"
|
2013-08-05 15:05:02 -07:00
|
|
|
elsif ARGV.include? '--opensuse'
|
|
|
|
exec_browser "http://software.opensuse.org/search?q=#{ARGV.next}"
|
2013-07-15 10:56:38 -05:00
|
|
|
elsif (query = ARGV.first).nil?
|
|
|
|
puts_columns Formula.names
|
2010-11-14 03:52:59 +00:00
|
|
|
else
|
2013-06-12 14:48:16 -05:00
|
|
|
rx = query_regexp(query)
|
2013-06-12 14:48:17 -05:00
|
|
|
local_results = search_formulae(rx)
|
|
|
|
puts_columns(local_results)
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2013-07-15 10:56:38 -05:00
|
|
|
if not query.empty? and $stdout.tty? and msg = blacklisted?(query)
|
2013-06-12 14:48:17 -05:00
|
|
|
unless local_results.empty?
|
2010-11-14 03:52:59 +00:00
|
|
|
puts
|
2013-06-12 14:48:16 -05:00
|
|
|
puts "If you meant #{query.inspect} precisely:"
|
2010-11-14 03:52:59 +00:00
|
|
|
puts
|
|
|
|
end
|
|
|
|
puts msg
|
|
|
|
end
|
2012-01-11 20:49:08 -06:00
|
|
|
|
2013-07-15 10:56:38 -05:00
|
|
|
tap_results = search_taps(rx)
|
|
|
|
puts_columns(tap_results)
|
|
|
|
count = local_results.length + tap_results.length
|
2012-03-16 22:37:11 +00:00
|
|
|
|
2013-07-15 10:56:38 -05:00
|
|
|
if count == 0 and not blacklisted? query
|
|
|
|
puts "No formula found for #{query.inspect}. Searching open pull requests..."
|
|
|
|
begin
|
|
|
|
GitHub.find_pull_requests(rx) { |pull| puts pull }
|
|
|
|
rescue GitHub::Error => e
|
|
|
|
opoo e.message
|
2012-03-20 16:03:27 +00:00
|
|
|
end
|
2012-01-11 20:49:08 -06:00
|
|
|
end
|
2010-11-14 03:52:59 +00:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
2013-06-12 14:48:17 -05:00
|
|
|
SEARCHABLE_TAPS = [
|
|
|
|
%w{josegonzalez php},
|
|
|
|
%w{samueljohn python},
|
2013-08-05 13:32:23 -07:00
|
|
|
%w{marcqualie nginx},
|
2013-06-12 14:48:17 -05:00
|
|
|
%w{Homebrew apache},
|
|
|
|
%w{Homebrew versions},
|
|
|
|
%w{Homebrew dupes},
|
|
|
|
%w{Homebrew games},
|
|
|
|
%w{Homebrew science},
|
|
|
|
%w{Homebrew completions},
|
|
|
|
%w{Homebrew x11},
|
2013-08-03 10:27:45 -07:00
|
|
|
%w{Homebrew binary},
|
2013-06-12 14:48:17 -05:00
|
|
|
]
|
|
|
|
|
2013-06-12 14:48:16 -05:00
|
|
|
def query_regexp(query)
|
|
|
|
case query
|
|
|
|
when %r{^/(.*)/$} then Regexp.new($1)
|
|
|
|
else /.*#{Regexp.escape(query)}.*/i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-12 14:48:17 -05:00
|
|
|
def search_taps(rx)
|
|
|
|
SEARCHABLE_TAPS.map do |user, repo|
|
|
|
|
Thread.new { search_tap(user, repo, rx) }
|
|
|
|
end.inject([]) do |results, t|
|
|
|
|
results.concat(t.value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-16 22:37:11 +00:00
|
|
|
def search_tap user, repo, rx
|
2012-03-18 02:03:19 +00:00
|
|
|
return [] if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}-#{repo.downcase}").directory?
|
2012-03-16 22:37:11 +00:00
|
|
|
|
|
|
|
results = []
|
2013-05-07 14:07:25 -04:00
|
|
|
GitHub.open "https://api.github.com/repos/#{user}/homebrew-#{repo}/git/trees/HEAD?recursive=1" do |f|
|
2013-05-18 08:34:28 -04:00
|
|
|
user.downcase! if user == "Homebrew" # special handling for the Homebrew organization
|
2013-06-22 16:51:08 -05:00
|
|
|
Utils::JSON.load(f.read)["tree"].map{ |hash| hash['path'] }.compact.each do |file|
|
2013-05-18 08:34:28 -04:00
|
|
|
name = File.basename(file, '.rb')
|
|
|
|
if file =~ /\.rb$/ and name =~ rx
|
|
|
|
results << "#{user}/#{repo}/#{name}"
|
2012-03-16 22:37:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
results
|
2013-07-28 15:38:01 -05:00
|
|
|
rescue GitHub::Error, Utils::JSON::Error
|
2013-07-01 16:58:16 -05:00
|
|
|
[]
|
2012-03-16 22:37:11 +00:00
|
|
|
end
|
|
|
|
|
2013-06-12 14:48:16 -05:00
|
|
|
def search_formulae rx
|
2013-07-15 10:56:38 -05:00
|
|
|
aliases = Formula.aliases
|
|
|
|
results = (Formula.names+aliases).grep(rx)
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2013-07-15 10:56:38 -05:00
|
|
|
# Filter out aliases when the full name was also found
|
|
|
|
results.reject do |alias_name|
|
|
|
|
if aliases.include? alias_name
|
|
|
|
resolved_name = (HOMEBREW_REPOSITORY+"Library/Aliases"+alias_name).readlink.basename('.rb').to_s
|
|
|
|
results.include? resolved_name
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|