| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2014-04-07 13:07:04 -05:00
										 |  |  |     recursive = ARGV.flag? "--recursive" | 
					
						
							| 
									
										
										
										
											2015-09-02 20:56:04 +08:00
										 |  |  |     ignores = [] | 
					
						
							| 
									
										
										
										
											2015-02-11 16:57:36 +08:00
										 |  |  |     ignores << "build?" if ARGV.include? "--skip-build" | 
					
						
							|  |  |  |     ignores << "optional?" if ARGV.include? "--skip-optional" | 
					
						
							| 
									
										
										
										
											2013-06-26 12:58:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 13:07:04 -05:00
										 |  |  |     uses = formulae.select do |f| | 
					
						
							| 
									
										
										
										
											2014-03-07 16:56:17 +01:00
										 |  |  |       used_formulae.all? do |ff| | 
					
						
							| 
									
										
										
										
											2014-12-27 13:03:13 +00:00
										 |  |  |         begin | 
					
						
							|  |  |  |           if recursive | 
					
						
							| 
									
										
										
										
											2015-05-19 21:57:45 +08:00
										 |  |  |             deps = f.recursive_dependencies do |dependent, dep| | 
					
						
							|  |  |  |               Dependency.prune if ignores.any? { |ignore| dep.send(ignore) } && !dependent.build.with?(dep) | 
					
						
							| 
									
										
										
										
											2015-09-02 20:56:04 +08:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2015-05-19 21:57:45 +08:00
										 |  |  |             reqs = f.recursive_requirements do |dependent, req| | 
					
						
							|  |  |  |               Requirement.prune if ignores.any? { |ignore| req.send(ignore) } && !dependent.build.with?(req) | 
					
						
							| 
									
										
										
										
											2015-05-19 21:40:04 +08:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2015-06-14 14:35:44 +08:00
										 |  |  |             deps.any? { |dep| dep.to_formula.full_name == ff.full_name rescue dep.name == ff.name } || | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |             reqs.any? { |req| req.name == ff.name || [ff.name, ff.full_name].include?(req.default_formula) } | 
					
						
							| 
									
										
										
										
											2014-12-27 13:03:13 +00:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2015-09-02 20:56:04 +08:00
										 |  |  |             deps = f.deps.reject do |dep| | 
					
						
							|  |  |  |               ignores.any? { |ignore| dep.send(ignore) } | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2015-05-19 21:40:04 +08:00
										 |  |  |             reqs = f.requirements.reject do |req| | 
					
						
							|  |  |  |               ignores.any? { |ignore| req.send(ignore) } | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2015-06-14 14:35:44 +08:00
										 |  |  |             deps.any? { |dep| dep.to_formula.full_name == ff.full_name rescue dep.name == ff.name } || | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |             reqs.any? { |req| req.name == ff.name || [ff.name, ff.full_name].include?(req.default_formula) } | 
					
						
							| 
									
										
										
										
											2014-12-27 13:03:13 +00:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-03-07 15:35:00 +00:00
										 |  |  |         rescue FormulaUnavailableError | 
					
						
							| 
									
										
										
										
											2014-12-27 13:03:13 +00:00
										 |  |  |           # Silently ignore this case as we don't care about things used in | 
					
						
							|  |  |  |           # taps that aren't currently tapped. | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 19:13:56 +08:00
										 |  |  |     puts_columns uses.map(&:full_name) | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |