Add alias support to formulae

* brew install will find an aliased formula
* aliases are searched against
* warn when creating a new formula that has an existing alias.

If Subversion has an alias "svn", then warn when the user tries to
create a new formula "svn". The formula can still be created, though
the user should make sure it's not a duplicate of the existing
aliased one.

Subversion and Objective-Caml formulas get some alises here, so we have
something to test against.
This commit is contained in:
Adam Vandenberg 2009-11-16 15:31:15 -08:00
parent af29299f37
commit 95e398ab13
3 changed files with 44 additions and 3 deletions

View File

@ -30,6 +30,13 @@ def __make url, name
path = Formula.path name path = Formula.path name
raise "#{path} already exists" if path.exist? raise "#{path} already exists" if path.exist?
# Check if a formula aliased to this name exists.
already_aka = Formulary.find_alias name
if already_aka != nil
opoo "Formula #{already_aka} is aliased to #{name}."
puts "Please check if you are creating a duplicate."
end
template=<<-EOS template=<<-EOS
require 'formula' require 'formula'

View File

@ -52,6 +52,22 @@ class Formulary
yield name, klass yield name, klass
end end
end end
def self.get_aliases
aliases = {}
Formulary.read_all do |name, klass|
aka = klass.aliases
next if aka == nil
aka.each {|item| aliases[item.to_s] = name }
end
return aliases
end
def self.find_alias name
aliases = Formulary.get_aliases
return aliases[name]
end
end end
@ -225,7 +241,15 @@ class Formula
require name require name
name = path.stem name = path.stem
else else
require self.path(name) begin
require self.path(name)
rescue LoadError => e
# Couldn't find formula 'name', so look for an alias.
real_name = Formulary.find_alias name
raise e if real_name == nil
puts "#{name} is an alias for #{real_name}"
name = real_name
end
end end
begin begin
klass_name =self.class_s(name) klass_name =self.class_s(name)
@ -418,7 +442,7 @@ private
end end
end end
attr_rw :url, :version, :homepage, :specs, :deps, *CHECKSUM_TYPES attr_rw :url, :version, :homepage, :specs, :deps, :aliases, *CHECKSUM_TYPES
def head val=nil, specs=nil def head val=nil, specs=nil
if specs if specs
@ -427,6 +451,14 @@ private
val.nil? ? @head : @head = val val.nil? ? @head : @head = val
end end
def aka *args
@aliases ||= []
args.each do |item|
@aliases << item.to_s
end
end
def depends_on name, *args def depends_on name, *args
@deps ||= [] @deps ||= []

View File

@ -98,7 +98,9 @@ begin
end end
when 'search', '-S' when 'search', '-S'
formulae = (HOMEBREW_REPOSITORY+'Library/Formula').children.sort.map{|f| f.basename('.rb') } require "formula"
formulae = Formulary.names with_aliases=true
if ARGV.first =~ /^\/(.*)\/$/ if ARGV.first =~ /^\/(.*)\/$/
puts_columns formulae.grep(Regexp.new($1)) puts_columns formulae.grep(Regexp.new($1))
else else