aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Contributions/examples/brew-missing.rb
blob: 21a0c071e5d44247791d5bbb8feff077a4279e97 (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
require "formula"
require "cmd/outdated"

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.installed?
  end
  formulae
end

def main
  return unless HOMEBREW_CELLAR.exist?

  # Names of outdated brews; they count as installed.
  outdated = Homebrew.outdated_brews.collect{ |b| b.name }

  formuale_to_check = ARGV.formulae rescue installed_brews

  formuale_to_check.each do |f|
    missing_deps = f.recursive_deps.map{ |g| g.name }.uniq.reject do |dep_name|
      Formula.factory(dep_name).installed? or outdated.include?(dep_name)
    end

    unless missing_deps.empty?
      print "#{f.name}: " if formuale_to_check.size > 1
      puts "#{missing_deps * ', '}"
    end
  end
end

main()