Merge pull request #1690 from reitermarkus/brew-cask-update

Deprecate `brew cask update`.
This commit is contained in:
Markus Reiter 2016-12-30 18:00:11 +01:00 committed by GitHub
commit e2689a697c
10 changed files with 47 additions and 39 deletions

View File

@ -19,7 +19,6 @@ require "hbc/cli/reinstall"
require "hbc/cli/search" require "hbc/cli/search"
require "hbc/cli/style" require "hbc/cli/style"
require "hbc/cli/uninstall" require "hbc/cli/uninstall"
require "hbc/cli/update"
require "hbc/cli/zap" require "hbc/cli/zap"
require "hbc/cli/internal_use_base" require "hbc/cli/internal_use_base"
@ -77,6 +76,7 @@ module Hbc
def self.command_classes def self.command_classes
@command_classes ||= constants.map(&method(:const_get)) @command_classes ||= constants.map(&method(:const_get))
.select { |sym| sym.respond_to?(:run) } .select { |sym| sym.respond_to?(:run) }
.sort_by(&:command_name)
end end
def self.commands def self.commands

View File

@ -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

View File

@ -1,3 +1,5 @@
require "tap"
module Hbc module Hbc
module Locations module Locations
def self.included(base) def self.included(base)

View File

@ -1 +1,2 @@
require "compat/hbc/cask_loader" require "compat/hbc/cask_loader"
require "compat/hbc/cli/update"

View File

@ -0,0 +1,23 @@
require "cask/lib/hbc/cli/base"
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.visible
false
end
def self.help
"a synonym for 'brew update'"
end
end
end
end

View File

@ -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 Uninstall the given Cask. With `--force`, uninstall even if the Cask
does not appear to be present. does not appear to be present.
* `update`:
For convenience. `brew cask update` is a synonym for `brew update`.
* `zap` <token> [ <token> ... ]: * `zap` <token> [ <token> ... ]:
Unconditionally remove _all_ files associated with the given Cask. Unconditionally remove _all_ files associated with the given Cask.

View File

@ -216,7 +216,7 @@ class UtilTests < Homebrew::TestCase
e = assert_raises(MethodDeprecatedError) do e = assert_raises(MethodDeprecatedError) do
odeprecated("method", "replacement", odeprecated("method", "replacement",
caller: ["#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/"], caller: ["#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/"],
die: true) disable: true)
end end
assert_match "method", e.message assert_match "method", e.message
assert_match "replacement", e.message assert_match "replacement", e.message

View File

@ -11,6 +11,7 @@ require "utils/hash"
require "utils/inreplace" require "utils/inreplace"
require "utils/popen" require "utils/popen"
require "utils/tty" require "utils/tty"
require "time"
def ohai(title, *sput) def ohai(title, *sput)
title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose? title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose?
@ -44,24 +45,32 @@ def odie(error)
exit 1 exit 1
end end
def odeprecated(method, replacement = nil, options = {}) def odeprecated(method, replacement = nil, disable: false, disable_on: nil, caller: send(:caller))
verb = if options[:die]
"disabled"
else
"deprecated"
end
replacement_message = if replacement replacement_message = if replacement
"Use #{replacement} instead." "Use #{replacement} instead."
else else
"There is no replacement." "There is no replacement."
end 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): # Try to show the most relevant location in message, i.e. (if applicable):
# - Location in a formula. # - Location in a formula.
# - Location outside of 'compat/'. # - Location outside of 'compat/'.
# - Location of caller of deprecated method (if all else fails). # - Location of caller of deprecated method (if all else fails).
backtrace = options.fetch(:caller, caller) backtrace = caller
tap_message = nil tap_message = nil
caller_message = backtrace.detect do |line| caller_message = backtrace.detect do |line|
next unless line =~ %r{^#{Regexp.escape HOMEBREW_LIBRARY}/Taps/([^/]+/[^/]+)/} next unless line =~ %r{^#{Regexp.escape HOMEBREW_LIBRARY}/Taps/([^/]+/[^/]+)/}
@ -80,7 +89,7 @@ def odeprecated(method, replacement = nil, options = {})
#{caller_message}#{tap_message} #{caller_message}#{tap_message}
EOS EOS
if ARGV.homebrew_developer? || options[:die] || if ARGV.homebrew_developer? || disable ||
Homebrew.raise_deprecation_exceptions? Homebrew.raise_deprecation_exceptions?
raise MethodDeprecatedError, message raise MethodDeprecatedError, message
else else
@ -89,7 +98,7 @@ def odeprecated(method, replacement = nil, options = {})
end end
def odisabled(method, replacement = nil, options = {}) def odisabled(method, replacement = nil, options = {})
options = { die: true, caller: caller }.merge(options) options = { disable: true, caller: caller }.merge(options)
odeprecated(method, replacement, options) odeprecated(method, replacement, options)
end end

View File

@ -43,7 +43,6 @@ __brew_cask_commands() {
'search:searches all known Casks' 'search:searches all known Casks'
'style:checks Cask style using RuboCop' 'style:checks Cask style using RuboCop'
'uninstall:uninstalls the given Cask' 'uninstall:uninstalls the given Cask'
"update:a synonym for 'brew update'"
'zap:zaps all files associated with the given Cask' 'zap:zaps all files associated with the given Cask'
) )
_describe -t commands "brew cask command" commands _describe -t commands "brew cask command" commands

View File

@ -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\. \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 .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\. \fBzap\fR \fItoken\fR [ \fItoken\fR \.\.\. ]: Unconditionally remove \fIall\fR files associated with the given Cask\.
. .
.IP .IP