aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/uses.rb
blob: 6775a55c0c65c81601233fbf2ce0e510a27a37e2 (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
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.select do |f|
      ARGV.formulae.all? do |ff|
        if ARGV.flag? '--recursive'
          f.recursive_dependencies.any? { |dep| dep.name == ff.name }
        else
          f.deps.any? { |dep| dep.name == ff.name }
        end
      end
    end

    if ARGV.include? "--installed"
      uses = uses.select { |f| Formula.installed.include? f }
    end

    puts_columns uses.map(&:to_s).sort
  end
end