2020-11-19 12:57:10 +01:00
|
|
|
# typed: true
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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"
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2020-06-24 11:59:55 -04:00
|
|
|
require "cask/cmd"
|
|
|
|
require "cask/cask_loader"
|
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
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(CLI::Parser) }
|
2018-11-11 17:43:31 +05:30
|
|
|
def uninstall_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2020-11-19 12:57:10 +01:00
|
|
|
`uninstall`, `rm`, `remove` [<options>] <formula>|<cask>
|
2018-11-11 17:43:31 +05:30
|
|
|
|
2020-11-19 12:57:10 +01:00
|
|
|
Uninstall a <formula> or <cask>.
|
2018-11-11 17:43:31 +05:30
|
|
|
EOS
|
2020-07-27 03:59:52 +02:00
|
|
|
switch "-f", "--force",
|
2020-11-19 12:57:10 +01:00
|
|
|
description: "Delete all installed versions of <formula>. Uninstall even if <cask> is not " \
|
|
|
|
"installed, overwrite existing files and ignore errors when removing files."
|
2018-11-11 17:43:31 +05:30
|
|
|
switch "--ignore-dependencies",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Don't fail uninstall, even if <formula> is a dependency of any installed "\
|
|
|
|
"formulae."
|
2020-07-30 18:40:10 +02:00
|
|
|
|
2020-11-18 16:39:07 +01:00
|
|
|
switch "--formula", "--formulae",
|
|
|
|
description: "Treat all named arguments as formulae."
|
|
|
|
switch "--cask", "--casks",
|
|
|
|
description: "Treat all named arguments as casks."
|
|
|
|
conflicts "--formula", "--cask"
|
|
|
|
|
2020-11-19 12:57:10 +01:00
|
|
|
min_named :formula_or_cask
|
2018-11-11 17:43:31 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def uninstall
|
2020-07-26 09:45:26 +02:00
|
|
|
args = uninstall_args.parse
|
2018-11-11 17:43:31 +05:30
|
|
|
|
2020-11-18 16:39:07 +01:00
|
|
|
only = :formula if args.formula? && !args.cask?
|
|
|
|
only = :cask if args.cask? && !args.formula?
|
|
|
|
|
2020-11-19 12:57:10 +01:00
|
|
|
all_kegs, casks = args.named.to_kegs_to_casks(only: only, ignore_unavailable: args.force?, all_kegs: args.force?)
|
|
|
|
kegs_by_rack = all_kegs.group_by(&:rack)
|
2020-07-02 15:28:41 -04:00
|
|
|
|
2020-11-19 12:57:10 +01:00
|
|
|
Uninstall.uninstall_kegs(
|
|
|
|
kegs_by_rack,
|
|
|
|
force: args.force?,
|
|
|
|
ignore_dependencies: args.ignore_dependencies?,
|
|
|
|
named_args: args.named,
|
|
|
|
)
|
2020-06-30 13:43:45 -04:00
|
|
|
|
2020-08-05 10:28:58 -04:00
|
|
|
Cask::Cmd::Uninstall.uninstall_casks(
|
|
|
|
*casks,
|
2020-08-01 02:30:46 +02:00
|
|
|
binaries: EnvConfig.cask_opts_binaries?,
|
2020-08-05 10:28:58 -04:00
|
|
|
verbose: args.verbose?,
|
|
|
|
force: args.force?,
|
|
|
|
)
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|