-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhbrew_deps
42 lines (38 loc) · 901 Bytes
/
hbrew_deps
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
#!/usr/bin/env ruby
#require 'optiflag'
deps = {}
ARGV.each {|arg| deps[arg] = []}
def check_em(deps)
installed = %x{brew list}.split("\n").map {|pkg| pkg + '.rb'}
brew = %x{brew --prefix}.chomp + '/Library/Formula'
Dir.chdir(brew)
installed.each do |formula|
File.open(formula, 'r').each do |line|
deps.keys.each do |dep|
if line.match(/depends_on\s+('|")#{dep}('|")/)
deps[dep].push(formula)
end
end
end
end
end
def show_em(deps)
deps.keys.each do |item|
if deps[item].empty?
puts "No dependents of #{item}"
else
puts "Installed dependents of #{item}:"
deps[item].each do |dep|
print " %s\n" % dep.gsub('.rb', '')
end
end
end
end
if deps.empty?
puts "Usage: $0 item1 item2 item3"
puts "You must give me at least one item to check on."
exit
else
check_em(deps)
show_em(deps)
end