implement formulary#find_with_priority
This commit is contained in:
parent
1a82b2133e
commit
194618beb8
@ -29,7 +29,11 @@ module Homebrew
|
|||||||
ARGV.named.each_with_index do |f, i|
|
ARGV.named.each_with_index do |f, i|
|
||||||
puts unless i == 0
|
puts unless i == 0
|
||||||
begin
|
begin
|
||||||
info_formula Formulary.factory(f)
|
if f.include?("/") || File.exist?(f)
|
||||||
|
info_formula Formulary.factory(f)
|
||||||
|
else
|
||||||
|
info_formula Formulary.find_with_priority(f)
|
||||||
|
end
|
||||||
rescue FormulaUnavailableError
|
rescue FormulaUnavailableError
|
||||||
# No formula with this name, try a blacklist lookup
|
# No formula with this name, try a blacklist lookup
|
||||||
if (blacklist = blacklisted?(f))
|
if (blacklist = blacklisted?(f))
|
||||||
|
|||||||
@ -13,7 +13,13 @@ module HomebrewArgvExtension
|
|||||||
|
|
||||||
def formulae
|
def formulae
|
||||||
require "formula"
|
require "formula"
|
||||||
@formulae ||= (downcased_unique_named - casks).map { |name| Formulary.factory(name, spec) }
|
@formulae ||= (downcased_unique_named - casks).map do |name|
|
||||||
|
if name.include?("/") || File.exist?(name)
|
||||||
|
Formulary.factory(name, spec)
|
||||||
|
else
|
||||||
|
Formulary.find_with_priority(name, spec)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolved_formulae
|
def resolved_formulae
|
||||||
|
|||||||
@ -250,9 +250,9 @@ class Formulary
|
|||||||
Pathname.new("#{HOMEBREW_LIBRARY}/Formula/#{name.downcase}.rb")
|
Pathname.new("#{HOMEBREW_LIBRARY}/Formula/#{name.downcase}.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.tap_paths(name)
|
def self.tap_paths(name, taps=Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/"])
|
||||||
name = name.downcase
|
name = name.downcase
|
||||||
Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/"].map do |tap|
|
taps.map do |tap|
|
||||||
Pathname.glob([
|
Pathname.glob([
|
||||||
"#{tap}Formula/#{name}.rb",
|
"#{tap}Formula/#{name}.rb",
|
||||||
"#{tap}HomebrewFormula/#{name}.rb",
|
"#{tap}HomebrewFormula/#{name}.rb",
|
||||||
@ -260,4 +260,22 @@ class Formulary
|
|||||||
]).detect(&:file?)
|
]).detect(&:file?)
|
||||||
end.compact
|
end.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.find_with_priority(ref, spec=:stable)
|
||||||
|
possible_pinned_tap_formulae = tap_paths(ref, Dir["#{HOMEBREW_LIBRARY}/PinnedTaps/*/*/"]).map(&:realpath)
|
||||||
|
if possible_pinned_tap_formulae.size > 1
|
||||||
|
raise TapFormulaAmbiguityError.new(ref, possible_pinned_tap_formulae)
|
||||||
|
elsif possible_pinned_tap_formulae.size == 1
|
||||||
|
selected_formula = factory(possible_pinned_tap_formulae.first, spec)
|
||||||
|
if core_path(ref).file?
|
||||||
|
opoo <<-EOS.undent
|
||||||
|
#{ref} is provided by core, but is now shadowed by #{selected_formula.full_name}.
|
||||||
|
To refer to the core formula, use Homebrew/homebrew/#{ref} instead.
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
selected_formula
|
||||||
|
else
|
||||||
|
factory(ref, spec)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user