brew/Library/Homebrew/cask/cmd/uninstall.rb

64 lines
1.7 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2018-09-06 08:29:14 +02:00
module Cask
2018-09-04 08:45:48 +01:00
class Cmd
2021-01-25 09:18:10 +00:00
# Cask implementation of the `brew uninstall` command.
2020-08-19 10:34:07 +02:00
#
# @api private
2017-05-20 19:08:03 +02:00
class Uninstall < AbstractCommand
2020-10-20 12:03:48 +02:00
extend T::Sig
2020-08-01 02:30:46 +02:00
def self.parser
super do
switch "--force",
description: "Uninstall even if the <cask> is not installed, overwrite " \
"existing files and ignore errors when removing files."
end
2017-05-20 03:57:38 +02:00
end
2016-08-18 22:11:42 +03:00
2020-10-20 12:03:48 +02:00
sig { void }
2017-05-20 03:57:38 +02:00
def run
self.class.uninstall_casks(
*casks,
2020-08-01 02:30:46 +02:00
binaries: args.binaries?,
verbose: args.verbose?,
force: args.force?,
)
end
2020-08-01 02:30:46 +02:00
def self.uninstall_casks(*casks, binaries: nil, force: false, verbose: false)
2020-08-18 00:23:23 +01:00
require "cask/installer"
2020-08-01 02:30:46 +02:00
options = {
binaries: binaries,
force: force,
verbose: verbose,
}.compact
casks.each do |cask|
odebug "Uninstalling Cask #{cask}"
2016-08-18 22:11:42 +03:00
if cask.installed?
2020-09-01 14:05:52 +01:00
if (installed_caskfile = cask.installed_caskfile) && installed_caskfile.exist?
# Use the same cask file that was used for installation, if possible.
2020-09-01 14:05:52 +01:00
cask = CaskLoader.load(installed_caskfile)
end
else
raise CaskNotInstalledError, cask unless force
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2020-08-01 02:30:46 +02:00
Installer.new(cask, **options).uninstall
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
next if (versions = cask.versions).empty?
2016-08-18 22:11:42 +03:00
2017-10-15 02:28:32 +02:00
puts <<~EOS
#{cask} #{versions.to_sentence} #{"is".pluralize(versions.count)} still installed.
2020-11-18 08:10:21 +01:00
Remove #{(versions.count == 1) ? "it" : "them all"} with `brew uninstall --cask --force #{cask}`.
2016-09-24 13:52:43 +02:00
EOS
end
end
end
2016-08-18 22:11:42 +03:00
end
end