improve TapLoader and TapFormulaUnavailableError
* Restore the ability to load formula by `user/homebrew-repo/foo`. * Only suggest to install tap when tap isn't installed. Closes Homebrew/homebrew#41705. Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
parent
86d04e94e9
commit
140f8e3df7
@ -51,17 +51,17 @@ class FormulaUnavailableError < RuntimeError
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TapFormulaUnavailableError < FormulaUnavailableError
|
class TapFormulaUnavailableError < FormulaUnavailableError
|
||||||
attr_reader :user, :repo, :shortname
|
attr_reader :tap
|
||||||
|
|
||||||
def initialize name
|
def initialize tap, name
|
||||||
super
|
@tap = tap
|
||||||
@user, @repo, @shortname = name.split("/", 3)
|
super "#{tap}/#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s; <<-EOS.undent
|
def to_s
|
||||||
No available formula for #{shortname} #{dependent_s}
|
s = super
|
||||||
Please tap it and then try again: brew tap #{user}/#{repo}
|
s += "\nPlease tap it and then try again: brew tap #{tap}" unless tap.installed?
|
||||||
EOS
|
s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -131,14 +131,13 @@ class Formulary
|
|||||||
|
|
||||||
# Loads tapped formulae.
|
# Loads tapped formulae.
|
||||||
class TapLoader < FormulaLoader
|
class TapLoader < FormulaLoader
|
||||||
attr_reader :tapped_name
|
attr_reader :tap
|
||||||
|
|
||||||
def initialize tapped_name
|
def initialize tapped_name
|
||||||
@tapped_name = tapped_name
|
|
||||||
user, repo, name = tapped_name.split("/", 3).map(&:downcase)
|
user, repo, name = tapped_name.split("/", 3).map(&:downcase)
|
||||||
tap = Tap.new user, repo
|
@tap = Tap.new user, repo.sub(/^homebrew-/, "")
|
||||||
path = tap.formula_files.detect { |file| file.basename(".rb").to_s == name }
|
path = @tap.formula_files.detect { |file| file.basename(".rb").to_s == name }
|
||||||
path ||= tap.path/"#{name}.rb"
|
path ||= @tap.path/"#{name}.rb"
|
||||||
|
|
||||||
super name, path
|
super name, path
|
||||||
end
|
end
|
||||||
@ -146,7 +145,7 @@ class Formulary
|
|||||||
def get_formula(spec)
|
def get_formula(spec)
|
||||||
super
|
super
|
||||||
rescue FormulaUnavailableError => e
|
rescue FormulaUnavailableError => e
|
||||||
raise TapFormulaUnavailableError, tapped_name, e.backtrace
|
raise TapFormulaUnavailableError.new(tap, name), "", e.backtrace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user