29 lines
757 B
Ruby
Raw Normal View History

require 'formula'
# `brew uses foo bar` now returns formula that use both foo and bar
# Rationale: If you want the union just run the command twice and
# concatenate the results.
# The intersection is harder to achieve with shell tools.
module Homebrew extend self
def uses
raise FormulaUnspecifiedError if ARGV.named.empty?
2012-01-29 21:42:09 -08:00
uses = Formula.select do |f|
ARGV.formulae.all? do |ff|
if ARGV.flag? '--recursive'
2013-01-23 00:26:29 -06:00
f.recursive_dependencies.any? { |dep| dep.name == ff.name }
else
2013-01-23 00:26:29 -06:00
f.deps.any? { |dep| dep.name == ff.name }
end
end
end
2012-01-29 21:42:09 -08:00
if ARGV.include? "--installed"
2013-01-23 00:26:29 -06:00
uses = uses.select { |f| Formula.installed.include? f }
end
2012-01-29 21:42:09 -08:00
2013-01-23 00:26:29 -06:00
puts_columns uses.map(&:to_s).sort
end
end