| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | require 'formula' | 
					
						
							| 
									
										
										
										
											2011-11-13 23:24:39 -06:00
										 |  |  | require 'tab' | 
					
						
							| 
									
										
										
										
											2012-01-01 15:27:21 -06:00
										 |  |  | require 'keg' | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew extend self | 
					
						
							|  |  |  |   def info | 
					
						
							|  |  |  |     if ARGV.named.empty? | 
					
						
							|  |  |  |       if ARGV.include? "--all" | 
					
						
							|  |  |  |         Formula.each do |f| | 
					
						
							|  |  |  |           info_formula f | 
					
						
							|  |  |  |           puts '---' | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         puts "#{HOMEBREW_CELLAR.children.length} kegs, #{HOMEBREW_CELLAR.abv}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     elsif valid_url ARGV[0] | 
					
						
							| 
									
										
										
										
											2011-03-14 10:55:15 -05:00
										 |  |  |       info_formula Formula.factory(ARGV.shift) | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     else | 
					
						
							|  |  |  |       ARGV.formulae.each{ |f| info_formula f } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def github_info name | 
					
						
							|  |  |  |     formula_name = Formula.path(name).basename | 
					
						
							|  |  |  |     user = 'mxcl' | 
					
						
							|  |  |  |     branch = 'master' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if system "/usr/bin/which -s git" | 
					
						
							|  |  |  |       gh_user=`git config --global github.user 2>/dev/null`.chomp | 
					
						
							| 
									
										
										
										
											2011-03-29 21:58:16 +02:00
										 |  |  |       /^\*\s*(.*)/.match(`git --git-dir=#{HOMEBREW_REPOSITORY}/.git branch 2>/dev/null`) | 
					
						
							| 
									
										
										
										
											2011-04-25 13:47:03 -05:00
										 |  |  |       unless $1.nil? || $1.empty? || $1.chomp == 'master' || gh_user.empty? | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |         branch = $1.chomp | 
					
						
							|  |  |  |         user = gh_user | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     "http://github.com/#{user}/homebrew/commits/#{branch}/Library/Formula/#{formula_name}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def info_formula f | 
					
						
							|  |  |  |     exec 'open', github_info(f.name) if ARGV.flag? '--github' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     puts "#{f.name} #{f.version}" | 
					
						
							|  |  |  |     puts f.homepage | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-21 13:57:09 -05:00
										 |  |  |     if f.keg_only? | 
					
						
							|  |  |  |       puts | 
					
						
							|  |  |  |       puts "This formula is keg-only." | 
					
						
							|  |  |  |       puts f.keg_only? | 
					
						
							|  |  |  |       puts | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     puts "Depends on: #{f.deps*', '}" unless f.deps.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-11 12:57:53 -07:00
										 |  |  |     if f.rack.directory? | 
					
						
							|  |  |  |       kegs = f.rack.children | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       kegs.each do |keg| | 
					
						
							|  |  |  |         next if keg.basename.to_s == '.DS_Store' | 
					
						
							|  |  |  |         print "#{keg} (#{keg.abv})" | 
					
						
							| 
									
										
										
										
											2012-01-01 15:27:21 -06:00
										 |  |  |         print " *" if Keg.new(keg).linked? and kegs.length > 1
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |         puts | 
					
						
							| 
									
										
										
										
											2012-01-01 15:26:45 -06:00
										 |  |  |         tab = Tab.for_keg keg | 
					
						
							|  |  |  |         unless tab.used_options.empty? | 
					
						
							|  |  |  |           puts "  Installed with: #{tab.used_options*', '}" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       puts "Not installed" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 20:11:54 -08:00
										 |  |  |     the_caveats = (f.caveats || "").strip | 
					
						
							|  |  |  |     unless the_caveats.empty? | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       puts | 
					
						
							|  |  |  |       puts f.caveats | 
					
						
							|  |  |  |       puts | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     history = github_info f.name | 
					
						
							|  |  |  |     puts history if history | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rescue FormulaUnavailableError | 
					
						
							|  |  |  |     # check for DIY installation | 
					
						
							| 
									
										
										
										
											2010-12-31 11:00:15 -08:00
										 |  |  |     d = HOMEBREW_PREFIX+name | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     if d.directory? | 
					
						
							|  |  |  |       ohai "DIY Installation" | 
					
						
							|  |  |  |       d.children.each{ |keg| puts "#{keg} (#{keg.abv})" } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       raise "No such formula or keg" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def valid_url u | 
					
						
							|  |  |  |     u[0..6] == 'http://' or u[0..7] == 'https://' or u[0..5] == 'ftp://' | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | end |