2014-06-19 17:52:42 -05:00
|
|
|
require "blacklist"
|
|
|
|
require "caveats"
|
|
|
|
require "cmd/options"
|
|
|
|
require "formula"
|
|
|
|
require "keg"
|
|
|
|
require "tab"
|
|
|
|
require "utils/json"
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2010-09-11 20:22:54 +01:00
|
|
|
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
|
2015-08-03 13:09:07 +01: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?
|
2015-08-13 20:35:22 +08:00
|
|
|
count = Formula.racks.length
|
2015-06-08 19:05:12 +08:00
|
|
|
puts "#{count} keg#{plural(count)}, #{HOMEBREW_CELLAR.abv}"
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
else
|
2015-08-03 13:09:07 +01:00
|
|
|
ARGV.named.each_with_index do |f, i|
|
2014-03-07 16:01:19 -08:00
|
|
|
puts unless i == 0
|
2013-04-29 10:12:40 -07:00
|
|
|
begin
|
2015-08-09 22:43:01 +08:00
|
|
|
if f.include?("/") || File.exist?(f)
|
|
|
|
info_formula Formulary.factory(f)
|
|
|
|
else
|
|
|
|
info_formula Formulary.find_with_priority(f)
|
|
|
|
end
|
2013-04-29 10:12:40 -07:00
|
|
|
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"
|
2015-08-03 13:09:07 +01:00
|
|
|
Formula
|
|
|
|
elsif ARGV.include? "--installed"
|
|
|
|
Formula.installed
|
|
|
|
else
|
|
|
|
ARGV.formulae
|
|
|
|
end
|
|
|
|
json = ff.map(&:to_hash)
|
2014-05-18 15:33:31 -07:00
|
|
|
puts Utils::JSON.dump(json)
|
2012-08-15 22:08:40 -05:00
|
|
|
end
|
|
|
|
|
2015-09-08 15:57:48 +08:00
|
|
|
def github_remote_path(remote, path)
|
|
|
|
if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$}
|
|
|
|
"https://github.com/#{$1}/#{$2}/blob/master/#{path}"
|
|
|
|
else
|
|
|
|
"#{remote}/#{path}"
|
2012-03-06 17:35:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def github_info(f)
|
2014-07-06 13:52:04 -05:00
|
|
|
if f.tap?
|
|
|
|
user, repo = f.tap.split("/", 2)
|
2015-09-27 16:52:14 +08:00
|
|
|
tap = Tap.fetch user, repo.gsub(/^homebrew-/, "")
|
2015-09-08 15:57:48 +08:00
|
|
|
if remote = tap.remote
|
|
|
|
path = f.path.relative_path_from(tap.path)
|
|
|
|
github_remote_path(remote, path)
|
|
|
|
else
|
|
|
|
f.path
|
|
|
|
end
|
2015-11-02 19:11:17 +08:00
|
|
|
elsif f.core_formula?
|
2015-09-08 15:57:48 +08:00
|
|
|
if remote = git_origin
|
|
|
|
path = f.path.relative_path_from(HOMEBREW_REPOSITORY)
|
|
|
|
github_remote_path(remote, path)
|
|
|
|
else
|
|
|
|
f.path
|
|
|
|
end
|
2015-11-02 19:11:17 +08:00
|
|
|
else
|
|
|
|
f.path
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
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
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
puts "#{f.full_name}: #{specs*", "}#{" (pinned)" if f.pinned?}"
|
2012-04-05 21:11:49 -05:00
|
|
|
|
2015-05-19 13:05:42 -04:00
|
|
|
puts f.desc if f.desc
|
|
|
|
|
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!
|
2015-08-03 13:09:07 +01: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|
|
2015-08-03 13:09:07 +01:00
|
|
|
puts "#{keg} (#{keg.abv})#{" *" if keg.linked?}"
|
2013-03-27 23:07:33 -05:00
|
|
|
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"
|
2015-08-03 13:09:07 +01:00
|
|
|
%w[build required recommended optional].map do |type|
|
cmd/info: prevent duplicate dependency display.
Before:
$ brew info llvm
==> Dependencies
Build: xz ✔, xz ✔, xz ✔, xz ✔, xz ✔, xz ✔
$ brew info --json=v1 llvm
... "dependencies":["xz","xz","xz","xz","xz","xz"], ...
After
$ brew info llvm
==> Dependencies
Build: xz ✔
$ brew info --json=v1 llvm
... "dependencies":["xz"], ...
Closes Homebrew/homebrew#36653.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
2015-02-08 23:20:45 +08:00
|
|
|
deps = f.deps.send(type).uniq
|
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
|
|
|
|
|
2014-08-10 21:45:24 -05:00
|
|
|
unless f.options.empty?
|
2012-08-04 15:40:36 -04:00
|
|
|
ohai "Options"
|
|
|
|
Homebrew.dump_options_for_formula f
|
|
|
|
end
|
|
|
|
|
2013-01-12 13:08:29 -06:00
|
|
|
c = Caveats.new(f)
|
2015-08-03 13:09:07 +01:00
|
|
|
ohai "Caveats", c.caveats unless c.empty?
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def decorate_dependencies(dependencies)
|
2013-11-11 14:15:46 +00:00
|
|
|
# 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
|
2015-08-03 13:09:07 +01: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
|