Add brew command 'uses'
'uses' shows the formulas that depend on a formula given on the command-line.
This commit is contained in:
parent
ed4992f467
commit
af29299f37
@ -201,6 +201,22 @@ class Formula
|
||||
name.capitalize.gsub(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase } \
|
||||
.gsub('+', 'x')
|
||||
end
|
||||
|
||||
def self.get_used_by
|
||||
used_by = {}
|
||||
Formulary.read_all do |name, klass|
|
||||
deps = klass.deps
|
||||
next if deps == nil
|
||||
|
||||
deps.each do |dep|
|
||||
_deps = used_by[dep] || []
|
||||
_deps << name unless _deps.include? name
|
||||
used_by[dep] = _deps
|
||||
end
|
||||
end
|
||||
|
||||
return used_by
|
||||
end
|
||||
|
||||
def self.factory name
|
||||
return name if name.kind_of? Formula
|
||||
|
||||
18
bin/brew
18
bin/brew
@ -226,6 +226,24 @@ begin
|
||||
when 'log'
|
||||
Dir.chdir HOMEBREW_REPOSITORY
|
||||
exec "git", "log", ARGV.formulae.first.path, *ARGV.options
|
||||
|
||||
when 'uses'
|
||||
# For each formula given, show which other formulas depend on it.
|
||||
# We only go one level up, direct dependencies.
|
||||
require 'formula'
|
||||
require 'utils'
|
||||
|
||||
deps = Formula.get_used_by
|
||||
|
||||
ARGV.formulae.each do |f|
|
||||
name = f.name
|
||||
our_deps = deps[name]
|
||||
if our_deps == nil
|
||||
puts "#{name} is not a dependency."
|
||||
else
|
||||
puts "#{name} is a dependency for #{our_deps.join(', ')}."
|
||||
end
|
||||
end
|
||||
|
||||
when 'pull', 'push', 'checkout', 'branch'
|
||||
onoe "Unknown command: #{arg} (did you mean 'git #{arg}'?)"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user