2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
module Cask
|
2018-09-04 08:45:48 +01:00
|
|
|
class Cmd
|
2020-08-19 10:34:07 +02:00
|
|
|
# Implementation of the `brew cask zap` command.
|
|
|
|
#
|
|
|
|
# @api private
|
2017-05-20 19:08:03 +02:00
|
|
|
class Zap < AbstractCommand
|
2020-08-01 02:30:46 +02:00
|
|
|
def self.min_named
|
|
|
|
:cask
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.description
|
|
|
|
<<~EOS
|
|
|
|
Zaps all files associated with the given <cask>. Implicitly also performs all actions associated with `uninstall`.
|
2017-07-30 18:51:05 +02:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
*May remove files which are shared between applications.*
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.parser
|
|
|
|
super do
|
|
|
|
switch "--force",
|
|
|
|
description: "Ignore errors when removing files."
|
|
|
|
end
|
2017-05-20 04:08:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2020-08-22 09:16:43 +08:00
|
|
|
require "cask/installer"
|
|
|
|
|
2017-06-13 17:14:01 +02:00
|
|
|
casks.each do |cask|
|
|
|
|
odebug "Zapping Cask #{cask}"
|
2018-04-28 20:12:55 +10:00
|
|
|
|
2020-08-26 01:56:49 +02:00
|
|
|
if cask.installed?
|
2020-09-01 14:05:52 +01:00
|
|
|
if (installed_caskfile = cask.installed_caskfile) && installed_caskfile.exist?
|
2020-08-26 01:56:49 +02:00
|
|
|
# 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)
|
2020-08-26 01:56:49 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
raise CaskNotInstalledError, cask unless args.force?
|
|
|
|
end
|
2018-04-28 20:12:55 +10:00
|
|
|
|
2020-08-01 02:30:46 +02:00
|
|
|
Installer.new(cask, verbose: args.verbose?, force: args.force?).zap
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|