From 0f8cb4ba277968fb24bf438468b37466075fd18a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 16 Dec 2016 19:39:12 +0100 Subject: [PATCH 1/7] Add option to disable methods on specific date. --- Library/Homebrew/test/utils_test.rb | 2 +- Library/Homebrew/utils.rb | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/test/utils_test.rb b/Library/Homebrew/test/utils_test.rb index 146f57b495..d7c25683d7 100644 --- a/Library/Homebrew/test/utils_test.rb +++ b/Library/Homebrew/test/utils_test.rb @@ -216,7 +216,7 @@ class UtilTests < Homebrew::TestCase e = assert_raises(MethodDeprecatedError) do odeprecated("method", "replacement", caller: ["#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/"], - die: true) + disable: true) end assert_match "method", e.message assert_match "replacement", e.message diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 4ad97c7d48..614d50eeae 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -11,6 +11,7 @@ require "utils/hash" require "utils/inreplace" require "utils/popen" require "utils/tty" +require "time" def ohai(title, *sput) title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose? @@ -44,24 +45,32 @@ def odie(error) exit 1 end -def odeprecated(method, replacement = nil, options = {}) - verb = if options[:die] - "disabled" - else - "deprecated" - end - +def odeprecated(method, replacement = nil, disable: false, disable_on: nil, caller: send(:caller)) replacement_message = if replacement "Use #{replacement} instead." else "There is no replacement." end + unless disable_on.nil? + if disable_on > Time.now + will_be_disabled_message = " and will be disabled on #{disable_on.strftime("%Y-%m-%d")}" + else + disable = true + end + end + + verb = if disable + "disabled" + else + "deprecated#{will_be_disabled_message}" + end + # Try to show the most relevant location in message, i.e. (if applicable): # - Location in a formula. # - Location outside of 'compat/'. # - Location of caller of deprecated method (if all else fails). - backtrace = options.fetch(:caller, caller) + backtrace = caller tap_message = nil caller_message = backtrace.detect do |line| next unless line =~ %r{^#{Regexp.escape HOMEBREW_LIBRARY}/Taps/([^/]+/[^/]+)/} @@ -80,7 +89,7 @@ def odeprecated(method, replacement = nil, options = {}) #{caller_message}#{tap_message} EOS - if ARGV.homebrew_developer? || options[:die] || + if ARGV.homebrew_developer? || disable || Homebrew.raise_deprecation_exceptions? raise MethodDeprecatedError, message else @@ -89,7 +98,7 @@ def odeprecated(method, replacement = nil, options = {}) end def odisabled(method, replacement = nil, options = {}) - options = { die: true, caller: caller }.merge(options) + options = { disable: true, caller: caller }.merge(options) odeprecated(method, replacement, options) end From a1154e9fabcca4feca629f86e86d139768f0de48 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 16 Dec 2016 19:40:10 +0100 Subject: [PATCH 2/7] Deprecate `brew cask update`. --- Library/Homebrew/cask/lib/hbc/cli.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/update.rb | 20 -------------------- Library/Homebrew/compat/hbc/cli/update.rb | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 21 deletions(-) delete mode 100644 Library/Homebrew/cask/lib/hbc/cli/update.rb create mode 100644 Library/Homebrew/compat/hbc/cli/update.rb diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index c9625c7e20..f1057566ef 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -19,7 +19,7 @@ require "hbc/cli/reinstall" require "hbc/cli/search" require "hbc/cli/style" require "hbc/cli/uninstall" -require "hbc/cli/update" +require "compat/hbc/cli/update" require "hbc/cli/zap" require "hbc/cli/internal_use_base" diff --git a/Library/Homebrew/cask/lib/hbc/cli/update.rb b/Library/Homebrew/cask/lib/hbc/cli/update.rb deleted file mode 100644 index 86d02bb55b..0000000000 --- a/Library/Homebrew/cask/lib/hbc/cli/update.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Hbc - class CLI - class Update < Base - def self.run(*_ignored) - result = SystemCommand.run(HOMEBREW_BREW_FILE, - args: ["update"]) - # TODO: separating stderr/stdout is undesirable here. - # Hbc::SystemCommand should have an option for plain - # unbuffered output. - print result.stdout - $stderr.print result.stderr - exit result.exit_status - end - - def self.help - "a synonym for 'brew update'" - end - end - end -end diff --git a/Library/Homebrew/compat/hbc/cli/update.rb b/Library/Homebrew/compat/hbc/cli/update.rb new file mode 100644 index 0000000000..32186472bf --- /dev/null +++ b/Library/Homebrew/compat/hbc/cli/update.rb @@ -0,0 +1,17 @@ +module Hbc + class CLI + class Update < Base + def self.run(*_ignored) + odeprecated "`brew cask update`", "`brew update`", disable_on: Time.utc(2017, 7, 1) + result = SystemCommand.run(HOMEBREW_BREW_FILE, args: ["update"], + print_stderr: true, + print_stdout: true) + exit result.exit_status + end + + def self.help + "a synonym for 'brew update'" + end + end + end +end From 1745997a305d92b5fd26e2a557ca5f061684773a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 17 Dec 2016 17:11:31 +0100 Subject: [PATCH 3/7] Remove `brew cask update` from manpage. --- Library/Homebrew/manpages/brew-cask.1.md | 3 --- manpages/brew-cask.1 | 3 --- 2 files changed, 6 deletions(-) diff --git a/Library/Homebrew/manpages/brew-cask.1.md b/Library/Homebrew/manpages/brew-cask.1.md index feab9f76e6..f0a70d4a76 100644 --- a/Library/Homebrew/manpages/brew-cask.1.md +++ b/Library/Homebrew/manpages/brew-cask.1.md @@ -104,9 +104,6 @@ names, and other aspects of this manual are still subject to change. Uninstall the given Cask. With `--force`, uninstall even if the Cask does not appear to be present. - * `update`: - For convenience. `brew cask update` is a synonym for `brew update`. - * `zap` [ ... ]: Unconditionally remove _all_ files associated with the given Cask. diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index af5335f796..9eaaf027a0 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -89,9 +89,6 @@ If \fItoken\fR is given, summarize the staged files associated with the given Ca \fBuninstall\fR or \fBrm\fR or \fBremove\fR [\-\-force] \fItoken\fR [ \fItoken\fR \.\.\. ]: Uninstall the given Cask\. With \fB\-\-force\fR, uninstall even if the Cask does not appear to be present\. . .IP "\(bu" 4 -\fBupdate\fR: For convenience\. \fBbrew cask update\fR is a synonym for \fBbrew update\fR\. -. -.IP "\(bu" 4 \fBzap\fR \fItoken\fR [ \fItoken\fR \.\.\. ]: Unconditionally remove \fIall\fR files associated with the given Cask\. . .IP From b11f38659a9799b3670655677216e0176de3a765 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 17 Dec 2016 17:13:04 +0100 Subject: [PATCH 4/7] Add warning to `brew cask help`. --- Library/Homebrew/compat/hbc/cli/update.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/compat/hbc/cli/update.rb b/Library/Homebrew/compat/hbc/cli/update.rb index 32186472bf..ab161ea652 100644 --- a/Library/Homebrew/compat/hbc/cli/update.rb +++ b/Library/Homebrew/compat/hbc/cli/update.rb @@ -10,7 +10,7 @@ module Hbc end def self.help - "a synonym for 'brew update'" + Formatter.warning("deprecated: use `brew update` instead") end end end From ddaf17396e4d0888ed2429821a94990800bd0814 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 30 Dec 2016 10:40:21 +0100 Subject: [PATCH 5/7] Remove `brew cask update` from ZSH completions. --- completions/zsh/_brew_cask | 1 - 1 file changed, 1 deletion(-) diff --git a/completions/zsh/_brew_cask b/completions/zsh/_brew_cask index bb64a2e32b..1e493fc2a6 100644 --- a/completions/zsh/_brew_cask +++ b/completions/zsh/_brew_cask @@ -43,7 +43,6 @@ __brew_cask_commands() { 'search:searches all known Casks' 'style:checks Cask style using RuboCop' 'uninstall:uninstalls the given Cask' - "update:a synonym for 'brew update'" 'zap:zaps all files associated with the given Cask' ) _describe -t commands "brew cask command" commands From cea1d18f45608dda5d3185659b790df1c5d1b4e7 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 30 Dec 2016 16:13:09 +0100 Subject: [PATCH 6/7] =?UTF-8?q?Do=20not=20require=20`compat/hbc/cli/update?= =?UTF-8?q?`=20when=20`=E2=80=94no-compat`=20is=20specified.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/cask/lib/hbc/cli.rb | 2 +- Library/Homebrew/cask/lib/hbc/locations.rb | 2 ++ Library/Homebrew/compat/hbc.rb | 1 + Library/Homebrew/compat/hbc/cli/update.rb | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index f1057566ef..42c3982ba8 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -19,7 +19,6 @@ require "hbc/cli/reinstall" require "hbc/cli/search" require "hbc/cli/style" require "hbc/cli/uninstall" -require "compat/hbc/cli/update" require "hbc/cli/zap" require "hbc/cli/internal_use_base" @@ -77,6 +76,7 @@ module Hbc def self.command_classes @command_classes ||= constants.map(&method(:const_get)) .select { |sym| sym.respond_to?(:run) } + .sort_by(&:command_name) end def self.commands diff --git a/Library/Homebrew/cask/lib/hbc/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb index f28e84b2ef..292b45d0ca 100644 --- a/Library/Homebrew/cask/lib/hbc/locations.rb +++ b/Library/Homebrew/cask/lib/hbc/locations.rb @@ -1,3 +1,5 @@ +require "tap" + module Hbc module Locations def self.included(base) diff --git a/Library/Homebrew/compat/hbc.rb b/Library/Homebrew/compat/hbc.rb index a1d1414a59..179639953e 100644 --- a/Library/Homebrew/compat/hbc.rb +++ b/Library/Homebrew/compat/hbc.rb @@ -1 +1,2 @@ require "compat/hbc/cask_loader" +require "compat/hbc/cli/update" diff --git a/Library/Homebrew/compat/hbc/cli/update.rb b/Library/Homebrew/compat/hbc/cli/update.rb index ab161ea652..80f9612280 100644 --- a/Library/Homebrew/compat/hbc/cli/update.rb +++ b/Library/Homebrew/compat/hbc/cli/update.rb @@ -1,3 +1,5 @@ +require "cask/lib/hbc/cli/base" + module Hbc class CLI class Update < Base From c31f959ec1955999d4be4446914eaab2e715058a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 30 Dec 2016 16:46:27 +0100 Subject: [PATCH 7/7] Hide `update` from `brew cask help`. --- Library/Homebrew/compat/hbc/cli/update.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/compat/hbc/cli/update.rb b/Library/Homebrew/compat/hbc/cli/update.rb index 80f9612280..7820997cbb 100644 --- a/Library/Homebrew/compat/hbc/cli/update.rb +++ b/Library/Homebrew/compat/hbc/cli/update.rb @@ -11,8 +11,12 @@ module Hbc exit result.exit_status end + def self.visible + false + end + def self.help - Formatter.warning("deprecated: use `brew update` instead") + "a synonym for 'brew update'" end end end