brew/Library/Contributions/cmd/brew-which.rb
Mike McQuaid 07f0f60908 Deprecate some contributions.
This is just a starting point to start discussion. I think we have a
few options with contributions:

- Stop accepting them altogether and move the ones we need/use/support
  into core commands
- Accept them on an unsupported basis and require they be added
  manually to the PATH
- Actively support and fix bugs in them all

Closes Homebrew/homebrew#30749.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
2014-07-10 10:24:17 -07:00

56 lines
1.4 KiB
Ruby
Executable File

require 'extend/pathname'
module Homebrew
def which_versions which_brews=nil
opoo <<-EOS.undent
brew which is unsupported and will be removed soon.
You should use `brew list --versions` instead.
To query other formula information see:
https://github.com/Homebrew/homebrew/wiki/Querying-Brew
Please feel free volunteer to support it in a tap.
EOS
brew_links = Array.new
version_map = Hash.new
real_cellar = HOMEBREW_CELLAR.realpath
(HOMEBREW_PREFIX/'opt').subdirs.each do |path|
next unless path.symlink? && path.resolved_path_exists?
brew_links << Pathname.new(path.realpath)
end
brew_links = brew_links.collect{|p|p.relative_path_from(real_cellar).to_s}.reject{|p|p.start_with?("../")}
brew_links.each do |p|
parts = p.split("/")
next if parts.count < 2 # Shouldn't happen for normally installed brews
brew = parts.shift
version = parts.shift
next unless which_brews.include? brew if which_brews
versions = version_map[brew] || []
versions << version unless versions.include? version
version_map[brew] = versions
end
return version_map
end
def which
which_brews = ARGV.named.empty? ? nil : ARGV.named
brews = which_versions which_brews
brews.keys.sort.each do |b|
puts "#{b}: #{brews[b].sort*' '}"
end
puts
end
end
Homebrew.which