aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2016-07-27 15:30:17 -0600
committerMike McQuaid2016-07-29 21:21:29 -0600
commit10ddb2ed974d351d8675216152c18f492e624af4 (patch)
tree900e82ab47ecb6bdc57ca6c50d8ecc90701b0910 /Library
parentaf2101b64d2ee709d8164d54ab8799cd26e406fc (diff)
downloadbrew-10ddb2ed974d351d8675216152c18f492e624af4.tar.bz2
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/`.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/utils.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 86c83f9f9..928f25fc9 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -112,6 +112,40 @@ def odie(error)
exit 1
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)
if !$stdout.tty?
"#{f}"