Merge pull request #13116 from issyl0/reinstall-cask-zap

cask/reinstall: Support `--zap` for entirely purging cask files
This commit is contained in:
Issy Long 2022-04-12 10:37:58 +01:00 committed by GitHub
commit a8ce086844
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 6 deletions

View File

@ -13,6 +13,10 @@ module Cask
[:switch, "--skip-cask-deps", {
description: "Skip installing cask dependencies.",
}],
[:switch, "--zap", {
description: "For use with `brew reinstall --cask`. Remove all files associated with a cask. " \
"*May remove files which are shared between applications.*",
}],
].freeze
def self.parser(&block)
@ -39,6 +43,7 @@ module Cask
require_sha: args.require_sha?,
quarantine: args.quarantine?,
quiet: args.quiet?,
zap: args.zap?,
)
end
@ -50,7 +55,8 @@ module Cask
skip_cask_deps: nil,
require_sha: nil,
quarantine: nil,
quiet: nil
quiet: nil,
zap: nil
)
odie "Installing casks is supported only on macOS" unless OS.mac?
@ -61,6 +67,7 @@ module Cask
skip_cask_deps: skip_cask_deps,
require_sha: require_sha,
quarantine: quarantine,
zap: zap,
}.compact
options[:quarantine] = true if options[:quarantine].nil?

View File

@ -19,6 +19,7 @@ module Cask
skip_cask_deps: args.skip_cask_deps?,
require_sha: args.require_sha?,
quarantine: args.quarantine?,
zap: args.zap?,
)
end
@ -29,7 +30,8 @@ module Cask
skip_cask_deps: nil,
binaries: nil,
require_sha: nil,
quarantine: nil
quarantine: nil,
zap: nil
)
require "cask/installer"
@ -40,6 +42,7 @@ module Cask
skip_cask_deps: skip_cask_deps,
require_sha: require_sha,
quarantine: quarantine,
zap: zap,
}.compact
options[:quarantine] = true if options[:quarantine].nil?

View File

@ -29,7 +29,7 @@ module Cask
def initialize(cask, command: SystemCommand, force: false,
skip_cask_deps: false, binaries: true, verbose: false,
require_sha: false, upgrade: false,
zap: false, require_sha: false, upgrade: false,
installed_as_dependency: false, quarantine: true,
verify_download_integrity: true, quiet: false)
@cask = cask
@ -38,6 +38,7 @@ module Cask
@skip_cask_deps = skip_cask_deps
@binaries = binaries
@verbose = verbose
@zap = zap
@require_sha = require_sha
@reinstall = false
@upgrade = upgrade
@ -48,7 +49,7 @@ module Cask
end
attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?,
:reinstall?, :upgrade?, :verbose?, :installed_as_dependency?,
:reinstall?, :upgrade?, :verbose?, :zap?, :installed_as_dependency?,
:quarantine?, :quiet?
def self.caveats(cask)
@ -157,7 +158,8 @@ module Cask
installed_cask = installed_caskfile.exist? ? CaskLoader.load(installed_caskfile) : @cask
# Always force uninstallation, ignore method parameter
Installer.new(installed_cask, verbose: verbose?, force: true, upgrade: upgrade?).uninstall
cask_installer = Installer.new(installed_cask, verbose: verbose?, force: true, upgrade: upgrade?)
zap? ? cask_installer.zap : cask_installer.uninstall
end
sig { returns(String) }

View File

@ -159,6 +159,7 @@ module Homebrew
require_sha: args.require_sha?,
skip_cask_deps: args.skip_cask_deps?,
quarantine: args.quarantine?,
zap: args.zap?,
)
end

View File

@ -108,7 +108,12 @@ describe Cask::Cmd::List, :cask do
"artifacts": [
[
"Caffeine.app"
]
],
{
"trash": "$HOME/support/fixtures/cask/caffeine/org.example.caffeine.plist",
"signal": {
}
}
],
"caveats": null,
"depends_on": {

View File

@ -24,6 +24,31 @@ describe Cask::Cmd::Reinstall, :cask do
}.to output(output).to_stdout
end
it "displays the reinstallation progress with zapping" do
caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))
Cask::Installer.new(caffeine).install
output = Regexp.new <<~EOS
==> Downloading file:.*caffeine.zip
Already downloaded: .*--caffeine.zip
==> Implied `brew uninstall --cask local-caffeine`
==> Backing App 'Caffeine.app' up to '.*Caffeine.app'
==> Removing App '.*Caffeine.app'
==> Dispatching zap stanza
==> Trashing files:
.*org\.example\.caffeine\.plist
==> Removing all staged versions of Cask 'local-caffeine'
==> Installing Cask local-caffeine
==> Moving App 'Caffeine.app' to '.*Caffeine.app'
.*local-caffeine was successfully installed!
EOS
expect {
described_class.run("local-caffeine", "--zap")
}.to output(output).to_stdout
end
it "allows reinstalling a Cask" do
Cask::Cmd::Install.run("local-transmission")

View File

@ -6,4 +6,6 @@ cask "local-caffeine" do
homepage "https://brew.sh/"
app "Caffeine.app"
zap trash: "#{TEST_FIXTURE_DIR}/cask/caffeine/org.example.caffeine.plist"
end