2016-04-08 16:28:43 +02:00
|
|
|
#: * `info` <formula>:
|
|
|
|
#: Display information about <formula>.
|
|
|
|
#:
|
|
|
|
#: * `info` `--github` <formula>:
|
|
|
|
#: Open a browser to the GitHub History page for formula <formula>.
|
|
|
|
#:
|
|
|
|
#: To view formula history locally: `brew log -p <formula>`.
|
|
|
|
#:
|
|
|
|
#: * `info` `--json=`<version> (`--all`|`--installed`|<formulae>):
|
|
|
|
#: Print a JSON representation of <formulae>. Currently the only accepted value
|
|
|
|
#: for <version> is `v1`.
|
|
|
|
#:
|
|
|
|
#: Pass `--all` to get information on all formulae, or `--installed` to get
|
|
|
|
#: information on all installed formulae.
|
|
|
|
#:
|
|
|
|
#: See the docs for examples of using the JSON:
|
2017-01-04 11:13:41 +00:00
|
|
|
#: <http://docs.brew.sh/Querying-Brew.html>
|
2016-04-08 16:28:43 +02:00
|
|
|
|
2014-06-19 17:52:42 -05:00
|
|
|
require "blacklist"
|
|
|
|
require "caveats"
|
2015-12-27 19:12:27 +01:00
|
|
|
require "options"
|
2014-06-19 17:52:42 -05:00
|
|
|
require "formula"
|
|
|
|
require "keg"
|
|
|
|
require "tab"
|
2016-11-20 13:00:01 -05:00
|
|
|
require "json"
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
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|
|
2016-09-10 10:24:56 +01:00
|
|
|
puts unless i.zero?
|
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
|
2016-09-22 20:12:28 +02:00
|
|
|
raise unless (blacklist = blacklisted?(f))
|
|
|
|
puts blacklist
|
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)
|
2016-11-20 13:00:01 -05:00
|
|
|
puts JSON.generate(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)
|
2015-12-06 22:24:46 +08:00
|
|
|
if f.tap
|
|
|
|
if remote = f.tap.remote
|
|
|
|
path = f.path.relative_path_from(f.tap.path)
|
2015-09-08 15:57:48 +08:00
|
|
|
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-11-16 20:10:25 +08:00
|
|
|
attrs = []
|
|
|
|
attrs << "pinned at #{f.pinned_version}" if f.pinned?
|
|
|
|
attrs << "keg-only" if f.keg_only?
|
2012-04-05 21:11:49 -05:00
|
|
|
|
2016-08-05 22:01:32 +08:00
|
|
|
puts "#{f.full_name}: #{specs * ", "}#{" [#{attrs * ", "}]" unless attrs.empty?}"
|
2015-05-19 13:05:42 -04:00
|
|
|
puts f.desc if f.desc
|
2016-08-30 21:38:13 +02:00
|
|
|
puts Formatter.url(f.homepage) if f.homepage
|
2011-06-21 13:57:09 -05:00
|
|
|
|
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
|
|
|
|
2015-11-29 15:28:58 +08:00
|
|
|
kegs = f.installed_kegs.sort_by(&:version)
|
2016-08-05 22:01:32 +08:00
|
|
|
if kegs.empty?
|
|
|
|
puts "Not installed"
|
|
|
|
else
|
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
|
|
|
|
end
|
|
|
|
|
2016-08-30 21:38:13 +02:00
|
|
|
puts "From: #{Formatter.url(github_info(f))}"
|
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
|
|
|
|
|
2016-09-18 00:12:49 -04:00
|
|
|
unless f.requirements.to_a.empty?
|
|
|
|
ohai "Requirements"
|
|
|
|
%w[build required recommended optional].map do |type|
|
|
|
|
reqs = f.requirements.select(&:"#{type}?")
|
2016-09-18 00:37:02 -04:00
|
|
|
next if reqs.to_a.empty?
|
|
|
|
puts "#{type.capitalize}: #{decorate_requirements(reqs)}"
|
2016-09-18 00:12:49 -04: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
|
|
|
deps_status = dependencies.collect do |dep|
|
2016-10-17 04:13:48 -04:00
|
|
|
if dep.satisfied?([])
|
|
|
|
pretty_installed(dep_display_s(dep))
|
|
|
|
else
|
|
|
|
pretty_uninstalled(dep_display_s(dep))
|
|
|
|
end
|
2013-11-11 14:15:46 +00:00
|
|
|
end
|
2016-10-17 04:13:48 -04:00
|
|
|
deps_status.join(", ")
|
2013-11-11 14:15:46 +00:00
|
|
|
end
|
2016-09-18 00:12:49 -04:00
|
|
|
|
|
|
|
def decorate_requirements(requirements)
|
|
|
|
req_status = requirements.collect do |req|
|
2016-09-18 00:37:02 -04:00
|
|
|
req_s = req.display_s
|
|
|
|
req.satisfied? ? pretty_installed(req_s) : pretty_uninstalled(req_s)
|
2016-09-18 00:12:49 -04:00
|
|
|
end
|
2016-09-18 00:37:02 -04:00
|
|
|
req_status.join(", ")
|
2016-09-18 00:12:49 -04:00
|
|
|
end
|
2016-10-17 04:13:48 -04:00
|
|
|
|
|
|
|
def dep_display_s(dep)
|
|
|
|
return dep.name if dep.option_tags.empty?
|
|
|
|
"#{dep.name} #{dep.option_tags.map { |o| "--#{o}" }.join(" ")}"
|
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|