2010-09-11 20:22:54 +01:00
|
|
|
require 'formula'
|
2011-11-13 23:24:39 -06:00
|
|
|
require 'tab'
|
2012-01-01 15:27:21 -06:00
|
|
|
require 'keg'
|
2013-01-01 17:26:50 +00:00
|
|
|
require 'caveats'
|
2013-04-29 10:12:40 -07:00
|
|
|
require 'blacklist'
|
2013-06-22 16:51:08 -05:00
|
|
|
require 'utils/json'
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def info
|
2012-08-15 22:08:40 -05:00
|
|
|
# eventually we'll solidify an API, but we'll keep old versions
|
|
|
|
# awhile around for compatibility
|
|
|
|
if ARGV.json == "v1"
|
|
|
|
print_json
|
2013-02-16 21:20:14 -06:00
|
|
|
elsif ARGV.flag? '--github'
|
2013-03-28 17:37:29 -05:00
|
|
|
exec_browser(*ARGV.formulae.map { |f| github_info(f) })
|
2012-08-15 22:08:40 -05:00
|
|
|
else
|
|
|
|
print_info
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def print_info
|
2010-09-11 20:22:54 +01:00
|
|
|
if ARGV.named.empty?
|
2014-03-08 07:34:27 -08:00
|
|
|
if HOMEBREW_CELLAR.exist?
|
2010-09-11 20:22:54 +01:00
|
|
|
puts "#{HOMEBREW_CELLAR.children.length} kegs, #{HOMEBREW_CELLAR.abv}"
|
|
|
|
end
|
|
|
|
else
|
2014-03-07 16:01:19 -08:00
|
|
|
ARGV.named.each_with_index do |f,i|
|
|
|
|
puts unless i == 0
|
2013-04-29 10:12:40 -07:00
|
|
|
begin
|
|
|
|
info_formula Formula.factory(f)
|
|
|
|
rescue FormulaUnavailableError
|
|
|
|
# No formula with this name, try a blacklist lookup
|
2013-05-02 21:34:48 -05:00
|
|
|
if (blacklist = blacklisted?(f))
|
|
|
|
puts blacklist
|
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
2013-04-29 10:12:40 -07:00
|
|
|
end
|
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-15 22:08:40 -05:00
|
|
|
def print_json
|
2014-05-16 08:47:09 -07:00
|
|
|
ff = if ARGV.include? "--all"
|
|
|
|
Formula
|
|
|
|
elsif ARGV.include? "--installed"
|
|
|
|
Formula.installed
|
|
|
|
else
|
|
|
|
ARGV.formulae
|
|
|
|
end
|
|
|
|
json = ff.map {|f| f.to_hash}
|
2014-05-18 15:33:31 -07:00
|
|
|
puts Utils::JSON.dump(json)
|
2012-08-15 22:08:40 -05:00
|
|
|
end
|
|
|
|
|
2012-03-06 17:35:10 +00:00
|
|
|
def github_fork
|
2012-08-06 16:44:11 -04:00
|
|
|
if which 'git' and (HOMEBREW_REPOSITORY/".git").directory?
|
2012-04-15 14:20:54 +01:00
|
|
|
if `git remote -v` =~ %r{origin\s+(https?://|git(?:@|://))github.com[:/](.+)/homebrew}
|
2012-03-06 17:35:10 +00:00
|
|
|
$2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-06 23:40:54 -05:00
|
|
|
def github_info f
|
2014-04-06 00:31:07 -05:00
|
|
|
if f.path.to_s =~ HOMEBREW_TAP_PATH_REGEX
|
2012-03-06 17:35:10 +00:00
|
|
|
user = $1
|
2014-04-24 11:26:45 +09:00
|
|
|
repo = $2
|
2012-03-06 17:35:10 +00:00
|
|
|
path = $3
|
|
|
|
else
|
2014-04-06 00:31:07 -05:00
|
|
|
user = f.path.parent.cd { github_fork }
|
2012-03-06 17:35:10 +00:00
|
|
|
repo = "homebrew"
|
2014-04-06 00:31:07 -05:00
|
|
|
path = "Library/Formula/#{f.path.basename}"
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
2013-06-25 11:21:04 -07:00
|
|
|
"https://github.com/#{user}/#{repo}/commits/master/#{path}"
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def info_formula f
|
2012-04-05 21:11:49 -05:00
|
|
|
specs = []
|
2014-03-10 14:56:02 -05:00
|
|
|
|
|
|
|
if stable = f.stable
|
|
|
|
s = "stable #{stable.version}"
|
|
|
|
s += " (bottled)" if stable.bottled?
|
|
|
|
specs << s
|
|
|
|
end
|
|
|
|
|
|
|
|
if devel = f.devel
|
2014-03-18 22:58:58 -05:00
|
|
|
s = "devel #{devel.version}"
|
2014-03-10 14:56:02 -05:00
|
|
|
s += " (bottled)" if devel.bottled?
|
|
|
|
specs << s
|
|
|
|
end
|
|
|
|
|
2012-04-05 21:11:49 -05:00
|
|
|
specs << "HEAD" if f.head
|
|
|
|
|
2013-03-31 12:27:11 +02:00
|
|
|
puts "#{f.name}: #{specs*', '}#{' (pinned)' if f.pinned?}"
|
2012-04-05 21:11:49 -05:00
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
puts f.homepage
|
|
|
|
|
2011-06-21 13:57:09 -05:00
|
|
|
if f.keg_only?
|
|
|
|
puts
|
|
|
|
puts "This formula is keg-only."
|
2012-08-09 02:00:58 -05:00
|
|
|
puts f.keg_only_reason
|
2011-06-21 13:57:09 -05:00
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
2013-06-09 13:44:59 -05:00
|
|
|
conflicts = f.conflicts.map(&:name).sort!
|
2012-07-28 13:02:46 -03:00
|
|
|
puts "Conflicts with: #{conflicts*', '}" unless conflicts.empty?
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2011-09-11 12:57:53 -07:00
|
|
|
if f.rack.directory?
|
2013-05-10 23:45:07 -05:00
|
|
|
kegs = f.rack.subdirs.map { |keg| Keg.new(keg) }.sort_by(&:version)
|
2010-09-11 20:22:54 +01:00
|
|
|
kegs.each do |keg|
|
2013-03-27 23:07:33 -05:00
|
|
|
puts "#{keg} (#{keg.abv})#{' *' if keg.linked?}"
|
|
|
|
tab = Tab.for_keg(keg).to_s
|
|
|
|
puts " #{tab}" unless tab.empty?
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
puts "Not installed"
|
|
|
|
end
|
|
|
|
|
2012-04-06 23:40:54 -05:00
|
|
|
history = github_info(f)
|
2013-06-25 11:21:04 -07:00
|
|
|
puts "From: #{history}" if history
|
2012-03-06 17:35:10 +00:00
|
|
|
|
2013-05-10 23:45:06 -05:00
|
|
|
unless f.deps.empty?
|
|
|
|
ohai "Dependencies"
|
|
|
|
%w{build required recommended optional}.map do |type|
|
|
|
|
deps = f.deps.send(type)
|
2013-11-11 14:15:46 +00:00
|
|
|
puts "#{type.capitalize}: #{decorate_dependencies deps}" unless deps.empty?
|
2013-05-10 23:45:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-09 09:24:07 -07:00
|
|
|
unless f.build.empty?
|
2012-08-04 15:40:36 -04:00
|
|
|
require 'cmd/options'
|
|
|
|
ohai "Options"
|
|
|
|
Homebrew.dump_options_for_formula f
|
|
|
|
end
|
|
|
|
|
2013-01-12 13:08:29 -06:00
|
|
|
c = Caveats.new(f)
|
|
|
|
ohai 'Caveats', c.caveats unless c.empty?
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
2013-11-11 14:15:46 +00:00
|
|
|
def decorate_dependencies dependencies
|
|
|
|
# necessary for 1.8.7 unicode handling since many installs are on 1.8.7
|
2013-11-11 22:15:24 +00:00
|
|
|
tick = ["2714".hex].pack("U*")
|
|
|
|
cross = ["2718".hex].pack("U*")
|
2013-11-11 14:15:46 +00:00
|
|
|
|
|
|
|
deps_status = dependencies.collect do |dep|
|
2013-11-11 22:15:24 +00:00
|
|
|
if dep.installed?
|
|
|
|
color = Tty.green
|
|
|
|
symbol = tick
|
|
|
|
else
|
|
|
|
color = Tty.red
|
|
|
|
symbol = cross
|
|
|
|
end
|
2013-11-11 14:15:46 +00:00
|
|
|
if ENV['HOMEBREW_NO_EMOJI']
|
2013-11-11 22:15:24 +00:00
|
|
|
colored_dep = "#{color}#{dep}"
|
2013-11-11 14:15:46 +00:00
|
|
|
else
|
2013-11-11 22:15:24 +00:00
|
|
|
colored_dep = "#{dep} #{color}#{symbol}"
|
2013-11-11 14:15:46 +00:00
|
|
|
end
|
2013-11-11 22:15:24 +00:00
|
|
|
"#{colored_dep}#{Tty.reset}"
|
2013-11-11 14:15:46 +00:00
|
|
|
end
|
|
|
|
deps_status * ", "
|
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|