aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2015-05-08 19:16:06 +0800
committerXu Cheng2015-05-27 13:53:40 +0800
commit811c4c5add5048e2e67814045e6d5fbb7820ddcb (patch)
tree6e4c866b1f11a788c0988e7402d9d223c24e2bb3 /Library
parent3a3a49bd93ee3a5a39019bb972a2a851ba2ab2f6 (diff)
downloadbrew-811c4c5add5048e2e67814045e6d5fbb7820ddcb.tar.bz2
load tap formula through direct search
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/exceptions.rb19
-rw-r--r--Library/Homebrew/formulary.rb15
2 files changed, 34 insertions, 0 deletions
diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb
index 663236cba..28a97bc82 100644
--- a/Library/Homebrew/exceptions.rb
+++ b/Library/Homebrew/exceptions.rb
@@ -65,6 +65,25 @@ class TapFormulaUnavailableError < FormulaUnavailableError
end
end
+class TapFormulaAmbiguityError < RuntimeError
+ attr_reader :name, :paths, :formulae
+
+ def initialize name, paths
+ @name = name
+ @paths = paths
+ @formulae = paths.map do |path|
+ path.to_s =~ HOMEBREW_TAP_PATH_REGEX
+ "#{$1}/#{$2.sub("homebrew-", "")}/#{path.basename(".rb")}"
+ end
+
+ super <<-EOS.undent
+ Formulae found in multiple taps: #{formulae.map { |f| "\n * #{f}" }.join}
+
+ Please use the fully-qualified name e.g. #{formulae.first} to refer the formula.
+ EOS
+ end
+end
+
class OperationInProgressError < RuntimeError
def initialize name
message = <<-EOS.undent
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index e59a25cc7..2a0d43f92 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -232,6 +232,13 @@ class Formulary
return AliasLoader.new(possible_alias)
end
+ possible_tap_formulae = tap_paths(ref)
+ if possible_tap_formulae.size > 1
+ raise TapFormulaAmbiguityError.new(ref, possible_tap_formulae)
+ elsif possible_tap_formulae.size == 1
+ return FormulaLoader.new(ref, possible_tap_formulae.first)
+ end
+
possible_cached_formula = Pathname.new("#{HOMEBREW_CACHE_FORMULA}/#{ref}.rb")
if possible_cached_formula.file?
return FormulaLoader.new(ref, possible_cached_formula)
@@ -243,4 +250,12 @@ class Formulary
def self.core_path(name)
Pathname.new("#{HOMEBREW_LIBRARY}/Formula/#{name.downcase}.rb")
end
+
+ def self.tap_paths(name)
+ name = name.downcase
+ Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/"].map do |tap|
+ Pathname.glob(["#{tap}#{name}.rb", "#{tap}Formula/#{name}.rb",
+ "#{tap}HomebrewFormula/#{name}.rb"])
+ end.flatten.select(&:file?)
+ end
end