| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2015-12-27 19:12:27 +01:00
										 |  |  | require "options" | 
					
						
							| 
									
										
										
										
											2014-06-19 17:52:42 -05:00
										 |  |  | 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| | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2015-11-16 20:10:25 +08:00
										 |  |  |     puts "#{Tty.em}#{f.homepage}#{Tty.reset}" 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-16 20:10:25 +08:00
										 |  |  |     puts "From: #{Tty.em}#{github_info(f)}#{Tty.reset}" | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     deps_status = dependencies.collect do |dep| | 
					
						
							| 
									
										
										
										
											2015-12-07 13:11:34 +00:00
										 |  |  |       dep.installed? ? pretty_installed(dep) : pretty_uninstalled(dep) | 
					
						
							| 
									
										
										
										
											2013-11-11 14:15:46 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |     deps_status * ", " | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | end |