aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/missing.rb
blob: 7f44170816dff921ae5a8c4267cc7a7fcf2d2c5b (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
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'formula'

module Homebrew extend self
  def installed_brews
    formulae = []
    HOMEBREW_CELLAR.subdirs.each do |rack|
      f = Formula.factory rack.basename.to_s rescue nil
      formulae << f if f and f.rack.exist? and f.rack.subdirs.length > 0
    end
    formulae
  end

  def missing_deps ff
    missing = {}
    ff.each do |f|
      missing_deps = f.recursive_deps.uniq.reject do |dep|
          dep.rack.exist? and dep.rack.subdirs.length > 0
        end

      unless missing_deps.empty?
        yield f.name, missing_deps if block_given?
        missing[f.name] = missing_deps
      end
    end
    missing
  end

  def missing
    return unless HOMEBREW_CELLAR.exist?

    ff = if ARGV.named.empty?
      installed_brews
    else
      ARGV.formulae
    end

    missing_deps(ff) do |name, missing|
      print "#{name}: " if ff.size > 1
      puts "#{missing * ' '}"
    end
  end
end