2013-06-11 22:23:19 -05:00
|
|
|
require 'formula'
|
|
|
|
require 'blacklist'
|
|
|
|
require 'utils'
|
|
|
|
require 'vendor/multi_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"
|
2010-11-14 03:52:59 +00:00
|
|
|
else
|
|
|
|
query = ARGV.first
|
2013-06-12 14:48:16 -05:00
|
|
|
rx = query_regexp(query)
|
2012-01-11 20:49:08 -06:00
|
|
|
search_results = search_brews rx
|
2010-11-14 03:52:59 +00:00
|
|
|
puts_columns search_results
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2011-03-09 20:50:01 -08:00
|
|
|
if not query.to_s.empty? and $stdout.tty? and msg = blacklisted?(query)
|
2010-11-14 03:52:59 +00:00
|
|
|
unless search_results.empty?
|
|
|
|
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
|
|
|
|
2012-03-20 16:03:27 +00:00
|
|
|
if query
|
|
|
|
$found = search_results.length
|
2012-03-25 11:06:28 +01:00
|
|
|
|
2012-08-08 22:25:04 +01:00
|
|
|
threads = []
|
|
|
|
results = []
|
|
|
|
threads << Thread.new { search_tap "josegonzalez", "php", rx }
|
2013-01-23 16:07:48 +01:00
|
|
|
threads << Thread.new { search_tap "samueljohn", "python", rx }
|
2013-01-30 22:15:37 -08:00
|
|
|
threads << Thread.new { search_tap "Homebrew", "apache", rx }
|
2012-08-08 22:25:04 +01:00
|
|
|
threads << Thread.new { search_tap "Homebrew", "versions", rx }
|
|
|
|
threads << Thread.new { search_tap "Homebrew", "dupes", rx }
|
|
|
|
threads << Thread.new { search_tap "Homebrew", "games", rx }
|
|
|
|
threads << Thread.new { search_tap "Homebrew", "science", rx }
|
2013-01-23 19:53:06 -08:00
|
|
|
threads << Thread.new { search_tap "Homebrew", "completions", rx }
|
2013-02-10 11:15:20 -08:00
|
|
|
threads << Thread.new { search_tap "Homebrew", "x11", rx }
|
2012-08-08 22:25:04 +01:00
|
|
|
|
|
|
|
threads.each do |t|
|
|
|
|
results << t.value
|
|
|
|
end
|
|
|
|
|
|
|
|
results.each { |r| puts_columns r }
|
2012-03-16 22:37:11 +00:00
|
|
|
|
2012-03-20 16:03:27 +00:00
|
|
|
if $found == 0 and not blacklisted? query
|
2013-06-12 14:48:16 -05:00
|
|
|
puts "No formula found for #{query.inspect}. Searching open pull requests..."
|
2012-03-20 16:03:27 +00:00
|
|
|
GitHub.find_pull_requests(rx) { |pull| puts pull }
|
|
|
|
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:16 -05:00
|
|
|
def query_regexp(query)
|
|
|
|
case query
|
|
|
|
when nil then ""
|
|
|
|
when %r{^/(.*)/$} then Regexp.new($1)
|
|
|
|
else /.*#{Regexp.escape(query)}.*/i
|
|
|
|
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
|
|
|
|
MultiJson.decode(f.read)["tree"].map{ |hash| hash['path'] }.compact.each do |file|
|
|
|
|
name = File.basename(file, '.rb')
|
|
|
|
if file =~ /\.rb$/ and name =~ rx
|
|
|
|
results << "#{user}/#{repo}/#{name}"
|
|
|
|
$found += 1
|
2012-03-16 22:37:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
results
|
|
|
|
end
|
|
|
|
|
2012-01-11 20:49:08 -06:00
|
|
|
def search_brews rx
|
|
|
|
if rx.to_s.empty?
|
2010-09-11 20:22:54 +01:00
|
|
|
Formula.names
|
|
|
|
else
|
|
|
|
aliases = Formula.aliases
|
|
|
|
results = (Formula.names+aliases).grep rx
|
|
|
|
|
|
|
|
# Filter out aliases when the full name was also found
|
|
|
|
results.reject do |alias_name|
|
|
|
|
if aliases.include? alias_name
|
2010-12-31 11:00:15 -08:00
|
|
|
resolved_name = (HOMEBREW_REPOSITORY+"Library/Aliases"+alias_name).readlink.basename('.rb').to_s
|
2010-09-11 20:22:54 +01:00
|
|
|
results.include? resolved_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|