| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | require 'formula' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-26 11:03:08 -07:00
										 |  |  | # `brew uses foo bar` returns formulae that use both foo and bar | 
					
						
							|  |  |  | # If you want the union, run the command twice and concatenate the results. | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | # The intersection is harder to achieve with shell tools. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew extend self | 
					
						
							|  |  |  |   def uses | 
					
						
							| 
									
										
										
										
											2012-02-04 00:01:29 -06:00
										 |  |  |     raise FormulaUnspecifiedError if ARGV.named.empty? | 
					
						
							| 
									
										
										
										
											2012-01-29 21:42:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-07 16:56:17 +01:00
										 |  |  |     used_formulae = ARGV.formulae | 
					
						
							|  |  |  |     formulae = (ARGV.include? "--installed") ? Formula.installed : Formula | 
					
						
							| 
									
										
										
										
											2013-06-26 12:58:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-29 17:27:36 -04:00
										 |  |  |     uses = [] | 
					
						
							| 
									
										
										
										
											2014-03-07 16:56:17 +01:00
										 |  |  |     formulae.each do |f| | 
					
						
							|  |  |  |       used_formulae.all? do |ff| | 
					
						
							| 
									
										
										
										
											2012-03-16 22:00:59 -07:00
										 |  |  |         if ARGV.flag? '--recursive' | 
					
						
							| 
									
										
										
										
											2013-10-29 17:27:36 -04:00
										 |  |  |           if f.recursive_dependencies.any? { |dep| dep.name == ff.name } | 
					
						
							|  |  |  |             uses << f.to_s | 
					
						
							|  |  |  |           elsif f.recursive_requirements.any? { |req| req.name == ff.name } | 
					
						
							| 
									
										
										
										
											2013-12-12 21:24:40 +00:00
										 |  |  |             uses << f.to_s | 
					
						
							| 
									
										
										
										
											2013-10-29 17:27:36 -04:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2012-03-16 22:00:59 -07:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2013-10-29 17:27:36 -04:00
										 |  |  |           if f.deps.any? { |dep| dep.name == ff.name } | 
					
						
							|  |  |  |             uses << f.to_s | 
					
						
							|  |  |  |           elsif f.requirements.any? { |req| req.name == ff.name } | 
					
						
							| 
									
										
										
										
											2013-12-12 21:24:40 +00:00
										 |  |  |             uses << f.to_s | 
					
						
							| 
									
										
										
										
											2013-10-29 17:27:36 -04:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2012-03-16 22:00:59 -07:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-01-29 21:42:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-29 17:27:36 -04:00
										 |  |  |     puts_columns uses | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |