2010-09-11 20:22:54 +01:00
|
|
|
require "formula"
|
2010-11-14 03:52:59 +00:00
|
|
|
require "blacklist"
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def search
|
|
|
|
if ARGV.include? '--macports'
|
|
|
|
exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
|
|
|
|
elsif ARGV.include? '--fink'
|
|
|
|
exec "open", "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}"
|
2010-11-14 03:52:59 +00:00
|
|
|
else
|
|
|
|
query = ARGV.first
|
2012-01-12 18:52:22 -06:00
|
|
|
rx = case query
|
|
|
|
when nil then ""
|
|
|
|
when %r{^/(.*)/$} then Regexp.new($1)
|
2012-01-11 20:49:08 -06:00
|
|
|
else
|
|
|
|
/.*#{Regexp.escape query}.*/i
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
puts "If you meant `#{query}' precisely:"
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
puts msg
|
|
|
|
end
|
2012-01-11 20:49:08 -06:00
|
|
|
|
2012-03-16 22:37:11 +00:00
|
|
|
$found = search_results.length
|
|
|
|
puts_columns search_tap "adamv", "alt", rx
|
|
|
|
puts_columns search_tap "josegonzalez", "php", rx
|
2012-03-18 01:23:15 +00:00
|
|
|
puts_columns search_tap "Homebrew", "versions", rx
|
|
|
|
puts_columns search_tap "Homebrew", "dupes", rx
|
2012-03-16 22:37:11 +00:00
|
|
|
|
|
|
|
if $found == 0 and not blacklisted? query
|
2012-01-12 21:10:03 -06:00
|
|
|
puts "No formula found for \"#{query}\". Searching open pull requests..."
|
|
|
|
GitHub.find_pull_requests(rx) { |pull| puts pull }
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
require 'open-uri'
|
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
results = []
|
|
|
|
open "http://github.com/api/v2/yaml/blob/all/#{user}/homebrew-#{repo}/master" do |f|
|
2012-03-18 01:51:36 +00:00
|
|
|
user.downcase! if user == "Homebrew" # special handling for the Homebrew organization
|
2012-03-16 22:37:11 +00:00
|
|
|
YAML::load(f.read)["blobs"].each do |file, _|
|
|
|
|
name = File.basename(file, '.rb')
|
|
|
|
if file =~ /\.rb$/ and name =~ rx
|
|
|
|
results << "#{user}/#{repo}/#{name}"
|
|
|
|
$found += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
results
|
|
|
|
rescue
|
|
|
|
[]
|
|
|
|
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
|