180 lines
4.6 KiB
Ruby
Raw Normal View History

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:
#: <https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Querying-Brew.md>
2014-06-19 17:52:42 -05:00
require "blacklist"
require "caveats"
require "options"
2014-06-19 17:52:42 -05:00
require "formula"
require "keg"
require "tab"
require "utils/json"
module Homebrew
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?
count = Formula.racks.length
2015-06-08 19:05:12 +08:00
puts "#{count} keg#{plural(count)}, #{HOMEBREW_CELLAR.abv}"
end
else
ARGV.named.each_with_index do |f, i|
2016-09-18 00:12:49 -04:00
puts unless i == 0
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
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
ff = if ARGV.include? "--all"
Formula
elsif ARGV.include? "--installed"
Formula.installed
else
ARGV.formulae
end
json = ff.map(&:to_hash)
puts Utils::JSON.dump(json)
end
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}"
end
end
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)
github_remote_path(remote, path)
else
f.path
end
else
f.path
end
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
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
puts "#{f.full_name}: #{specs * ", "}#{" [#{attrs * ", "}]" unless attrs.empty?}"
2015-05-19 13:05:42 -04:00
puts f.desc if f.desc
puts "#{Tty.em}#{f.homepage}#{Tty.reset}" if f.homepage
conflicts = f.conflicts.map(&:name).sort!
puts "Conflicts with: #{conflicts*", "}" unless conflicts.empty?
2015-11-29 15:28:58 +08:00
kegs = f.installed_kegs.sort_by(&:version)
if kegs.empty?
puts "Not installed"
else
kegs.each do |keg|
puts "#{keg} (#{keg.abv})#{" *" if keg.linked?}"
tab = Tab.for_keg(keg).to_s
puts " #{tab}" unless tab.empty?
end
end
puts "From: #{Tty.em}#{github_info(f)}#{Tty.reset}"
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).uniq
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}?")
puts "#{type.capitalize}: #{decorate_requirements(reqs)}" unless reqs.to_a.empty?
end
end
unless f.options.empty?
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)
deps_status = dependencies.collect do |dep|
dep.installed? ? pretty_installed(dep) : pretty_uninstalled(dep)
end
deps_status * ", "
end
2016-09-18 00:12:49 -04:00
def decorate_requirements(requirements)
req_status = requirements.collect do |req|
req.satisfied? ? pretty_installed(req.name) : pretty_uninstalled(req.name)
end
req_status * ", "
end
end