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:
parent
af29299f37
commit
95e398ab13
@ -29,6 +29,13 @@ def __make url, name
|
||||
|
||||
path = Formula.path name
|
||||
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
|
||||
require 'formula'
|
||||
|
||||
@ -52,6 +52,22 @@ class Formulary
|
||||
yield name, klass
|
||||
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
|
||||
|
||||
|
||||
@ -225,7 +241,15 @@ class Formula
|
||||
require name
|
||||
name = path.stem
|
||||
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
|
||||
begin
|
||||
klass_name =self.class_s(name)
|
||||
@ -418,7 +442,7 @@ private
|
||||
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
|
||||
if specs
|
||||
@ -426,6 +450,14 @@ private
|
||||
end
|
||||
val.nil? ? @head : @head = val
|
||||
end
|
||||
|
||||
def aka *args
|
||||
@aliases ||= []
|
||||
|
||||
args.each do |item|
|
||||
@aliases << item.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def depends_on name, *args
|
||||
@deps ||= []
|
||||
|
||||
4
bin/brew
4
bin/brew
@ -98,7 +98,9 @@ begin
|
||||
end
|
||||
|
||||
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 =~ /^\/(.*)\/$/
|
||||
puts_columns formulae.grep(Regexp.new($1))
|
||||
else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user