164 lines
3.7 KiB
Ruby
Raw Normal View History

require 'formula'
require 'tab'
require 'keg'
require 'caveats'
require 'blacklist'
require 'utils/json'
module Homebrew extend self
def info
# eventually we'll solidify an API, but we'll keep old versions
# awhile around for compatibility
if ARGV.json == "v1"
print_json
elsif ARGV.flag? '--github'
exec_browser(*ARGV.formulae.map { |f| github_info(f) })
else
print_info
end
end
def print_info
if ARGV.named.empty?
if HOMEBREW_CELLAR.exist?
puts "#{HOMEBREW_CELLAR.children.length} kegs, #{HOMEBREW_CELLAR.abv}"
end
else
ARGV.named.each do |f|
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
end
end
end
end
def print_json
formulae = ARGV.include?("--all") ? Formula : ARGV.formulae
json = formulae.map {|f| f.to_hash}
if json.size == 1
puts Utils::JSON.dump(json.pop)
else
puts Utils::JSON.dump(json)
end
end
def github_fork
if which 'git' and (HOMEBREW_REPOSITORY/".git").directory?
if `git remote -v` =~ %r{origin\s+(https?://|git(?:@|://))github.com[:/](.+)/homebrew}
$2
end
end
end
def github_info f
path = f.path.realpath
2013-10-30 11:19:28 -07:00
if path.to_s =~ HOMEBREW_TAP_PATH_REGEX
user = $1
repo = "homebrew-#$2"
path = $3
else
path.parent.cd do
user = github_fork
end
repo = "homebrew"
path = "Library/Formula/#{path.basename}"
end
"https://github.com/#{user}/#{repo}/commits/master/#{path}"
end
def info_formula f
2012-04-05 21:11:49 -05:00
specs = []
if stable = f.stable
s = "stable #{stable.version}"
s += " (bottled)" if stable.bottled?
specs << s
end
if devel = f.devel
s = "devel #{devel.version}"
s += " (bottled)" if devel.bottled?
specs << s
end
2012-04-05 21:11:49 -05:00
specs << "HEAD" if f.head
puts "#{f.name}: #{specs*', '}#{' (pinned)' if f.pinned?}"
2012-04-05 21:11:49 -05:00
puts f.homepage
if f.keg_only?
puts
puts "This formula is keg-only."
puts f.keg_only_reason
puts
end
conflicts = f.conflicts.map(&:name).sort!
puts "Conflicts with: #{conflicts*', '}" unless conflicts.empty?
if f.rack.directory?
2013-05-10 23:45:07 -05:00
kegs = f.rack.subdirs.map { |keg| Keg.new(keg) }.sort_by(&:version)
kegs.each do |keg|
puts "#{keg} (#{keg.abv})#{' *' if keg.linked?}"
tab = Tab.for_keg(keg).to_s
puts " #{tab}" unless tab.empty?
end
else
puts "Not installed"
end
history = github_info(f)
puts "From: #{history}" if history
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)
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?
require 'cmd/options'
ohai "Options"
Homebrew.dump_options_for_formula f
end
c = Caveats.new(f)
ohai 'Caveats', c.caveats unless c.empty?
end
def decorate_dependencies dependencies
# necessary for 1.8.7 unicode handling since many installs are on 1.8.7
tick = ["2714".hex].pack("U*")
cross = ["2718".hex].pack("U*")
deps_status = dependencies.collect do |dep|
if dep.installed?
color = Tty.green
symbol = tick
else
color = Tty.red
symbol = cross
end
if ENV['HOMEBREW_NO_EMOJI']
colored_dep = "#{color}#{dep}"
else
colored_dep = "#{dep} #{color}#{symbol}"
end
"#{colored_dep}#{Tty.reset}"
end
deps_status * ", "
end
end