2024-04-01 11:46:01 -07:00
|
|
|
# typed: strict
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
require "abstract_command"
|
2015-08-03 13:09:07 +01:00
|
|
|
require "keg"
|
|
|
|
require "formula"
|
2016-09-30 19:34:14 +01:00
|
|
|
require "diagnostic"
|
2015-08-09 14:57:15 +03:00
|
|
|
require "migrator"
|
2020-06-24 11:59:55 -04:00
|
|
|
require "cask/cask_loader"
|
2023-03-02 22:29:57 +09:00
|
|
|
require "cask/exceptions"
|
|
|
|
require "cask/installer"
|
2023-03-09 22:33:29 +09:00
|
|
|
require "cask/uninstall"
|
2020-11-01 14:45:11 -05:00
|
|
|
require "uninstall"
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2024-04-01 11:46:01 -07:00
|
|
|
module Cmd
|
|
|
|
class UninstallCmd < AbstractCommand
|
|
|
|
cmd_args do
|
|
|
|
description <<~EOS
|
|
|
|
Uninstall a <formula> or <cask>.
|
|
|
|
EOS
|
|
|
|
switch "-f", "--force",
|
|
|
|
description: "Delete all installed versions of <formula>. Uninstall even if <cask> is not " \
|
|
|
|
"installed, overwrite existing files and ignore errors when removing files."
|
|
|
|
switch "--zap",
|
|
|
|
description: "Remove all files associated with a <cask>. " \
|
|
|
|
"*May remove files which are shared between applications.*"
|
|
|
|
switch "--ignore-dependencies",
|
|
|
|
description: "Don't fail uninstall, even if <formula> is a dependency of any installed " \
|
|
|
|
"formulae."
|
|
|
|
switch "--formula", "--formulae",
|
|
|
|
description: "Treat all named arguments as formulae."
|
|
|
|
switch "--cask", "--casks",
|
|
|
|
description: "Treat all named arguments as casks."
|
2016-09-26 01:44:51 +02:00
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
conflicts "--formula", "--cask"
|
|
|
|
conflicts "--formula", "--zap"
|
2020-11-27 11:41:08 -05:00
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
named_args [:installed_formula, :installed_cask], min: 1
|
|
|
|
end
|
2018-11-11 17:43:31 +05:30
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
sig { override.void }
|
|
|
|
def run
|
|
|
|
all_kegs, casks = args.named.to_kegs_to_casks(
|
|
|
|
ignore_unavailable: args.force?,
|
|
|
|
all_kegs: args.force?,
|
|
|
|
)
|
2018-11-11 17:43:31 +05:30
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
# If ignore_unavailable is true and the named args
|
|
|
|
# are a series of invalid kegs and casks,
|
|
|
|
# #to_kegs_to_casks will return empty arrays.
|
|
|
|
return if all_kegs.blank? && casks.blank?
|
2020-11-18 16:39:07 +01:00
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
kegs_by_rack = all_kegs.group_by(&:rack)
|
2022-07-08 10:21:57 -07:00
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
Uninstall.uninstall_kegs(
|
|
|
|
kegs_by_rack,
|
|
|
|
casks:,
|
|
|
|
force: args.force?,
|
|
|
|
ignore_dependencies: args.ignore_dependencies?,
|
|
|
|
named_args: args.named,
|
|
|
|
)
|
2020-07-02 15:28:41 -04:00
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
if args.zap?
|
|
|
|
casks.each do |cask|
|
|
|
|
odebug "Zapping Cask #{cask}"
|
2020-06-30 13:43:45 -04:00
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
raise Cask::CaskNotInstalledError, cask if !cask.installed? && !args.force?
|
2023-03-02 22:29:57 +09:00
|
|
|
|
2024-04-01 11:46:01 -07:00
|
|
|
Cask::Installer.new(cask, verbose: args.verbose?, force: args.force?).zap
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Cask::Uninstall.uninstall_casks(
|
|
|
|
*casks,
|
|
|
|
verbose: args.verbose?,
|
|
|
|
force: args.force?,
|
|
|
|
)
|
|
|
|
end
|
2023-03-02 22:29:57 +09:00
|
|
|
|
2024-05-26 15:39:45 +01:00
|
|
|
if ENV["HOMEBREW_AUTOREMOVE"].present?
|
|
|
|
opoo "HOMEBREW_AUTOREMOVE is now a no-op as it is the default behaviour. " \
|
|
|
|
"Set HOMEBREW_NO_AUTOREMOVE=1 to disable it."
|
|
|
|
end
|
|
|
|
Cleanup.autoremove unless Homebrew::EnvConfig.no_autoremove?
|
2023-03-02 22:29:57 +09:00
|
|
|
end
|
2020-11-19 14:02:28 +01:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|