mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Support --cask
flag in brew uninstall
.
This commit is contained in:
parent
1cd1155dd2
commit
5097af3b74
@ -6,6 +6,7 @@ require "delegate"
|
|||||||
require "cask/cask_loader"
|
require "cask/cask_loader"
|
||||||
require "cli/args"
|
require "cli/args"
|
||||||
require "formulary"
|
require "formulary"
|
||||||
|
require "keg"
|
||||||
require "missing_formula"
|
require "missing_formula"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
@ -14,6 +15,8 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
class NamedArgs < Array
|
class NamedArgs < Array
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
def initialize(*args, parent: Args.new, override_spec: nil, force_bottle: false, flags: [])
|
def initialize(*args, parent: Args.new, override_spec: nil, force_bottle: false, flags: [])
|
||||||
@args = args
|
@args = args
|
||||||
@override_spec = override_spec
|
@override_spec = override_spec
|
||||||
@ -39,9 +42,9 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_formulae_to_casks(method: nil, only: nil)
|
def to_formulae_to_casks(only: nil, method: nil)
|
||||||
@to_formulae_to_casks ||= {}
|
@to_formulae_to_casks ||= {}
|
||||||
@to_formulae_to_casks[[method, only]] = to_formulae_and_casks(method: method, only: only)
|
@to_formulae_to_casks[[method, only]] = to_formulae_and_casks(only: only, method: method)
|
||||||
.partition { |o| o.is_a?(Formula) }
|
.partition { |o| o.is_a?(Formula) }
|
||||||
.map(&:freeze).freeze
|
.map(&:freeze).freeze
|
||||||
end
|
end
|
||||||
@ -62,14 +65,16 @@ module Homebrew
|
|||||||
when nil, :factory
|
when nil, :factory
|
||||||
Formulary.factory(name, *spec, force_bottle: @force_bottle, flags: @flags)
|
Formulary.factory(name, *spec, force_bottle: @force_bottle, flags: @flags)
|
||||||
when :resolve
|
when :resolve
|
||||||
Formulary.resolve(name, spec: spec, force_bottle: @force_bottle, flags: @flags)
|
resolve_formula(name)
|
||||||
|
when :keg
|
||||||
|
resolve_keg(name)
|
||||||
else
|
else
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
warn_if_cask_conflicts(name, "formula") unless only == :formula
|
warn_if_cask_conflicts(name, "formula") unless only == :formula
|
||||||
return formula
|
return formula
|
||||||
rescue FormulaUnavailableError => e
|
rescue NoSuchKegError, FormulaUnavailableError => e
|
||||||
raise e if only == :formula
|
raise e if only == :formula
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -97,7 +102,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_resolved_formulae_to_casks(only: nil)
|
def to_resolved_formulae_to_casks(only: nil)
|
||||||
to_formulae_to_casks(method: :resolve, only: only)
|
to_formulae_to_casks(only: only, method: :resolve)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert named arguments to {Formula} or {Cask} objects.
|
# Convert named arguments to {Formula} or {Cask} objects.
|
||||||
@ -105,7 +110,7 @@ module Homebrew
|
|||||||
# formula and prints a warning unless `only` is specified.
|
# formula and prints a warning unless `only` is specified.
|
||||||
def to_objects(only: nil, method: nil)
|
def to_objects(only: nil, method: nil)
|
||||||
@to_objects ||= {}
|
@to_objects ||= {}
|
||||||
@to_objects[only] ||= downcased_unique_named.flat_map do |name|
|
@to_objects[only] ||= downcased_unique_named.map do |name|
|
||||||
load_formula_or_cask(name, only: only, method: method)
|
load_formula_or_cask(name, only: only, method: method)
|
||||||
end.uniq.freeze
|
end.uniq.freeze
|
||||||
end
|
end
|
||||||
@ -142,44 +147,33 @@ module Homebrew
|
|||||||
end.uniq.freeze
|
end.uniq.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Keg]) }
|
||||||
def to_kegs
|
def to_kegs
|
||||||
@to_kegs ||= downcased_unique_named.map do |name|
|
@to_kegs ||= begin
|
||||||
resolve_keg name
|
to_formulae_and_casks(only: :formula, method: :keg).freeze
|
||||||
rescue NoSuchKegError => e
|
rescue NoSuchKegError => e
|
||||||
if (reason = Homebrew::MissingFormula.suggest_command(name, "uninstall"))
|
if (reason = Homebrew::MissingFormula.suggest_command(e.name, "uninstall"))
|
||||||
$stderr.puts reason
|
$stderr.puts reason
|
||||||
end
|
end
|
||||||
raise e
|
raise e
|
||||||
end.freeze
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_kegs_to_casks
|
|
||||||
@to_kegs_to_casks ||= begin
|
|
||||||
kegs = []
|
|
||||||
casks = []
|
|
||||||
|
|
||||||
downcased_unique_named.each do |name|
|
|
||||||
kegs << resolve_keg(name)
|
|
||||||
|
|
||||||
warn_if_cask_conflicts(name, "keg")
|
|
||||||
rescue NoSuchKegError, FormulaUnavailableError
|
|
||||||
begin
|
|
||||||
casks << Cask::CaskLoader.load(name, config: Cask::Config.from_args(@parent))
|
|
||||||
rescue Cask::CaskUnavailableError
|
|
||||||
raise "No installed keg or cask with the name \"#{name}\""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
[kegs.freeze, casks.freeze].freeze
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(only: Symbol).returns([T::Array[Keg], T::Array[Cask::Cask]]) }
|
||||||
|
def to_kegs_to_casks(only: nil)
|
||||||
|
@to_kegs_to_casks ||= to_formulae_and_casks(only: only, method: :keg)
|
||||||
|
.partition { |o| o.is_a?(Keg) }
|
||||||
|
.map(&:freeze).freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[String]) }
|
||||||
def homebrew_tap_cask_names
|
def homebrew_tap_cask_names
|
||||||
downcased_unique_named.grep(HOMEBREW_CASK_TAP_CASK_REGEX)
|
downcased_unique_named.grep(HOMEBREW_CASK_TAP_CASK_REGEX)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
sig { returns(T::Array[String]) }
|
||||||
def downcased_unique_named
|
def downcased_unique_named
|
||||||
# Only lowercase names, not paths, bottle filenames or URLs
|
# Only lowercase names, not paths, bottle filenames or URLs
|
||||||
map do |arg|
|
map do |arg|
|
||||||
|
@ -29,6 +29,12 @@ module Homebrew
|
|||||||
description: "Don't fail uninstall, even if <formula> is a dependency of any installed "\
|
description: "Don't fail uninstall, even if <formula> is a dependency of any installed "\
|
||||||
"formulae."
|
"formulae."
|
||||||
|
|
||||||
|
switch "--formula", "--formulae",
|
||||||
|
description: "Treat all named arguments as formulae."
|
||||||
|
switch "--cask", "--casks",
|
||||||
|
description: "Treat all named arguments as casks."
|
||||||
|
conflicts "--formula", "--cask"
|
||||||
|
|
||||||
min_named :formula
|
min_named :formula
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -36,25 +42,29 @@ module Homebrew
|
|||||||
def uninstall
|
def uninstall
|
||||||
args = uninstall_args.parse
|
args = uninstall_args.parse
|
||||||
|
|
||||||
|
only = :formula if args.formula? && !args.cask?
|
||||||
|
only = :cask if args.cask? && !args.formula?
|
||||||
|
|
||||||
if args.force?
|
if args.force?
|
||||||
casks = []
|
casks = []
|
||||||
kegs_by_rack = {}
|
kegs_by_rack = {}
|
||||||
|
|
||||||
args.named.each do |name|
|
args.named.each do |name|
|
||||||
rack = Formulary.to_rack(name)
|
if only != :cask
|
||||||
|
rack = Formulary.to_rack(name)
|
||||||
|
kegs_by_rack[rack] = rack.subdirs.map { |d| Keg.new(d) } if rack.directory?
|
||||||
|
end
|
||||||
|
|
||||||
if rack.directory?
|
next if only == :formula
|
||||||
kegs_by_rack[rack] = rack.subdirs.map { |d| Keg.new(d) }
|
|
||||||
else
|
begin
|
||||||
begin
|
casks << Cask::CaskLoader.load(name)
|
||||||
casks << Cask::CaskLoader.load(name)
|
rescue Cask::CaskUnavailableError
|
||||||
rescue Cask::CaskUnavailableError
|
# Since the uninstall was forced, ignore any unavailable casks.
|
||||||
# Since the uninstall was forced, ignore any unavailable casks
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
all_kegs, casks = args.named.to_kegs_to_casks
|
all_kegs, casks = args.named.to_kegs_to_casks(only: only)
|
||||||
kegs_by_rack = all_kegs.group_by(&:rack)
|
kegs_by_rack = all_kegs.group_by(&:rack)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -571,6 +571,10 @@ Uninstall *`formula`*.
|
|||||||
Delete all installed versions of *`formula`*.
|
Delete all installed versions of *`formula`*.
|
||||||
* `--ignore-dependencies`:
|
* `--ignore-dependencies`:
|
||||||
Don't fail uninstall, even if *`formula`* is a dependency of any installed formulae.
|
Don't fail uninstall, even if *`formula`* is a dependency of any installed formulae.
|
||||||
|
* `--formula`:
|
||||||
|
Treat all named arguments as formulae.
|
||||||
|
* `--cask`:
|
||||||
|
Treat all named arguments as casks.
|
||||||
|
|
||||||
### `unlink` [*`options`*] *`formula`*
|
### `unlink` [*`options`*] *`formula`*
|
||||||
|
|
||||||
|
@ -793,6 +793,14 @@ Delete all installed versions of \fIformula\fR\.
|
|||||||
\fB\-\-ignore\-dependencies\fR
|
\fB\-\-ignore\-dependencies\fR
|
||||||
Don\'t fail uninstall, even if \fIformula\fR is a dependency of any installed formulae\.
|
Don\'t fail uninstall, even if \fIformula\fR is a dependency of any installed formulae\.
|
||||||
.
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-\-formula\fR
|
||||||
|
Treat all named arguments as formulae\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-\-cask\fR
|
||||||
|
Treat all named arguments as casks\.
|
||||||
|
.
|
||||||
.SS "\fBunlink\fR [\fIoptions\fR] \fIformula\fR"
|
.SS "\fBunlink\fR [\fIoptions\fR] \fIformula\fR"
|
||||||
Remove symlinks for \fIformula\fR from Homebrew\'s prefix\. This can be useful for temporarily disabling a formula: \fBbrew unlink\fR \fIformula\fR \fB&&\fR \fIcommands\fR \fB&& brew link\fR \fIformula\fR
|
Remove symlinks for \fIformula\fR from Homebrew\'s prefix\. This can be useful for temporarily disabling a formula: \fBbrew unlink\fR \fIformula\fR \fB&&\fR \fIcommands\fR \fB&& brew link\fR \fIformula\fR
|
||||||
.
|
.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user