aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/uses.rb
blob: 63bfb09f9eaa91c43c5b7db2ec8896b98ba1cc6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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?

    uses = Formula.all.select do |f|
      ARGV.formulae.all? do |ff|
        # For each formula given, show which other formulas depend on it.
        # We only go one level up, ie. direct dependencies.
        f.deps.include? ff.name
      end
    end

    if ARGV.include? "--installed"
      uses = uses.select do |f|
        keg = HOMEBREW_CELLAR/f
        keg.directory? and not keg.subdirs.empty?
      end
    end

    puts_columns uses.map{|f| f.to_s}.sort
  end
end