utils: add API removal messaging methods.

Add new `odeprecated` and `odisabled` methods to print API removal
messages. Currently these are just used by things in `compat/`.
This commit is contained in:
Mike McQuaid 2016-07-27 15:30:17 -06:00
parent af2101b64d
commit 10ddb2ed97

View File

@ -112,6 +112,40 @@ def odie(error)
exit 1 exit 1
end end
def odeprecated(method, replacement = nil, options = {})
verb = if options[:die]
"disabled"
else
"deprecated"
end
replacement_message = if replacement
"Use #{replacement} instead."
else
"There is no replacement."
end
# Show the first location that's not in compat.
backtrace = options[:caller] || caller
caller_message = backtrace[1]
message = <<-EOS.undent
Calling #{method} is #{verb}!
#{replacement_message}
#{caller_message}
EOS
if ARGV.homebrew_developer? || options[:die]
raise FormulaMethodDeprecatedError.new message
else
opoo "#{message}\n"
end
end
def odisabled(method, replacement = nil, options = {})
odeprecated(method, replacement, :die => true, :caller => caller)
end
def pretty_installed(f) def pretty_installed(f)
if !$stdout.tty? if !$stdout.tty?
"#{f}" "#{f}"