From db328b59f274a69a4d24843cfccc6e3ddbe0f6e6 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Thu, 9 Mar 2023 22:33:29 +0900 Subject: [PATCH 1/4] move cask/cmd/uninstall to cask/uninstall --- Library/Homebrew/cask/cmd.rb | 1 - Library/Homebrew/cask/cmd/uninstall.rb | 56 -------------------------- Library/Homebrew/cask/uninstall.rb | 33 +++++++++++++++ Library/Homebrew/cmd/uninstall.rb | 4 +- 4 files changed, 35 insertions(+), 59 deletions(-) delete mode 100644 Library/Homebrew/cask/cmd/uninstall.rb create mode 100644 Library/Homebrew/cask/uninstall.rb diff --git a/Library/Homebrew/cask/cmd.rb b/Library/Homebrew/cask/cmd.rb index ec3921fa5f..0c9e74d0ef 100644 --- a/Library/Homebrew/cask/cmd.rb +++ b/Library/Homebrew/cask/cmd.rb @@ -14,7 +14,6 @@ require "cask/cmd/audit" require "cask/cmd/fetch" require "cask/cmd/install" require "cask/cmd/reinstall" -require "cask/cmd/uninstall" require "cask/cmd/upgrade" module Cask diff --git a/Library/Homebrew/cask/cmd/uninstall.rb b/Library/Homebrew/cask/cmd/uninstall.rb deleted file mode 100644 index 1700482a65..0000000000 --- a/Library/Homebrew/cask/cmd/uninstall.rb +++ /dev/null @@ -1,56 +0,0 @@ -# typed: false -# frozen_string_literal: true - -module Cask - class Cmd - # Cask implementation of the `brew uninstall` command. - # - # @api private - class Uninstall < AbstractCommand - extend T::Sig - - def self.parser - super do - switch "--force", - description: "Uninstall even if the is not installed, overwrite " \ - "existing files and ignore errors when removing files." - end - end - - sig { void } - def run - self.class.uninstall_casks( - *casks, - binaries: args.binaries?, - verbose: args.verbose?, - force: args.force?, - ) - end - - def self.uninstall_casks(*casks, binaries: nil, force: false, verbose: false) - require "cask/installer" - - options = { - binaries: binaries, - force: force, - verbose: verbose, - }.compact - - casks.each do |cask| - odebug "Uninstalling Cask #{cask}" - - raise CaskNotInstalledError, cask if !cask.installed? && !force - - Installer.new(cask, **options).uninstall - - next if (versions = cask.versions).empty? - - puts <<~EOS - #{cask} #{versions.to_sentence} #{(versions.count == 1) ? "is" : "are"} still installed. - Remove #{(versions.count == 1) ? "it" : "them all"} with `brew uninstall --cask --force #{cask}`. - EOS - end - end - end - end -end diff --git a/Library/Homebrew/cask/uninstall.rb b/Library/Homebrew/cask/uninstall.rb new file mode 100644 index 0000000000..0e9522b8e6 --- /dev/null +++ b/Library/Homebrew/cask/uninstall.rb @@ -0,0 +1,33 @@ +# typed: false +# frozen_string_literal: true + +module Cask + # @api private + class Uninstall + + def self.uninstall_casks(*casks, binaries: nil, force: false, verbose: false) + require "cask/installer" + + options = { + binaries: binaries, + force: force, + verbose: verbose, + }.compact + + casks.each do |cask| + odebug "Uninstalling Cask #{cask}" + + raise CaskNotInstalledError, cask if !cask.installed? && !force + + Installer.new(cask, **options).uninstall + + next if (versions = cask.versions).empty? + + puts <<~EOS + #{cask} #{versions.to_sentence} #{(versions.count == 1) ? "is" : "are"} still installed. + Remove #{(versions.count == 1) ? "it" : "them all"} with `brew uninstall --cask --force #{cask}`. + EOS + end + end + end +end diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index 9465360839..e0db1db786 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -6,10 +6,10 @@ require "formula" require "diagnostic" require "migrator" require "cli/parser" -require "cask/cmd" require "cask/cask_loader" require "cask/exceptions" require "cask/installer" +require "cask/uninstall" require "uninstall" module Homebrew @@ -76,7 +76,7 @@ module Homebrew Cask::Installer.new(cask, verbose: args.verbose?, force: args.force?).zap end else - T.unsafe(Cask::Cmd::Uninstall).uninstall_casks( + Cask::Uninstall.uninstall_casks( *casks, verbose: args.verbose?, force: args.force?, From cd0686d75b021aa7a7373b6e7d66cc17938771c2 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Thu, 9 Mar 2023 22:33:45 +0900 Subject: [PATCH 2/4] move cask/cmd/uninstall_spec to cask/uninstall_spec --- .../test/cask/{cmd => }/uninstall_spec.rb | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) rename Library/Homebrew/test/cask/{cmd => }/uninstall_spec.rb (81%) diff --git a/Library/Homebrew/test/cask/cmd/uninstall_spec.rb b/Library/Homebrew/test/cask/uninstall_spec.rb similarity index 81% rename from Library/Homebrew/test/cask/cmd/uninstall_spec.rb rename to Library/Homebrew/test/cask/uninstall_spec.rb index 5620e112e5..0d3340f883 100644 --- a/Library/Homebrew/test/cask/cmd/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/uninstall_spec.rb @@ -1,7 +1,9 @@ # typed: false # frozen_string_literal: true -describe Cask::Cmd::Uninstall, :cask do +require "cask/uninstall" + +describe Cask::Uninstall, :cask do it "displays the uninstallation progress" do caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) @@ -15,23 +17,22 @@ describe Cask::Cmd::Uninstall, :cask do EOS expect do - described_class.run("local-caffeine") + described_class.uninstall_casks(caffeine) end.to output(output).to_stdout end - it "shows an error when a bad Cask is provided" do - expect { described_class.run("notacask") } - .to raise_error(Cask::CaskUnavailableError, /is unavailable/) - end - it "shows an error when a Cask is provided that's not installed" do - expect { described_class.run("local-caffeine") } + caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) + + expect { described_class.uninstall_casks(caffeine) } .to raise_error(Cask::CaskNotInstalledError, /is not installed/) end it "tries anyway on a non-present Cask when --force is given" do + caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) + expect do - described_class.run("local-caffeine", "--force") + described_class.uninstall_casks(caffeine, force: true) end.not_to raise_error end @@ -45,7 +46,7 @@ describe Cask::Cmd::Uninstall, :cask do expect(caffeine).to be_installed expect(transmission).to be_installed - described_class.run("local-caffeine", "local-transmission") + described_class.uninstall_casks(caffeine, transmission) expect(caffeine).not_to be_installed expect(caffeine.config.appdir.join("Transmission.app")).not_to exist @@ -62,13 +63,13 @@ describe Cask::Cmd::Uninstall, :cask do cask.config.appdir.join("MyFancyApp.app").rmtree - expect { described_class.run("with-uninstall-script-app") } + expect { described_class.uninstall_casks(cask) } .to raise_error(Cask::CaskError, /uninstall script .* does not exist/) expect(cask).to be_installed expect do - described_class.run("with-uninstall-script-app", "--force") + described_class.uninstall_casks(cask, force: true) end.not_to raise_error expect(cask).not_to be_installed @@ -85,6 +86,7 @@ describe Cask::Cmd::Uninstall, :cask do ] end let(:caskroom_path) { Cask::Caskroom.path.join(token).tap(&:mkpath) } + # let(:versioned_cask) { Cask::CaskLoader.load(caskroom_path) } before do timestamped_versions.each do |timestamped_version| @@ -101,13 +103,13 @@ describe Cask::Cmd::Uninstall, :cask do end it "uninstalls one version at a time" do - described_class.run("versioned-cask") + described_class.uninstall_casks(Cask::Cask.new("versioned-cask")) expect(caskroom_path.join(first_installed_version)).to exist expect(caskroom_path.join(last_installed_version)).not_to exist expect(caskroom_path).to exist - described_class.run("versioned-cask") + described_class.uninstall_casks(Cask::Cask.new("versioned-cask")) expect(caskroom_path.join(first_installed_version)).not_to exist expect(caskroom_path).not_to exist @@ -116,7 +118,7 @@ describe Cask::Cmd::Uninstall, :cask do it "displays a message when versions remain installed" do expect do expect do - described_class.run("versioned-cask") + described_class.uninstall_casks(Cask::Cask.new("versioned-cask")) end.not_to output.to_stderr end.to output(/#{token} #{first_installed_version} is still installed./).to_stdout end @@ -125,6 +127,7 @@ describe Cask::Cmd::Uninstall, :cask do context "when Casks in Taps have been renamed or removed" do let(:app) { Cask::Config.new.appdir.join("ive-been-renamed.app") } let(:caskroom_path) { Cask::Caskroom.path.join("ive-been-renamed").tap(&:mkpath) } + # let(:ive_been_renamed) { Cask::CaskLoader.load(caskroom_path) } let(:saved_caskfile) do caskroom_path.join(".metadata", "latest", "timestamp", "Casks").join("ive-been-renamed.rb") end @@ -148,7 +151,7 @@ describe Cask::Cmd::Uninstall, :cask do end it "can still uninstall them" do - described_class.run("ive-been-renamed") + described_class.uninstall_casks(Cask::Cask.new("ive-been-renamed")) expect(app).not_to exist expect(caskroom_path).not_to exist From 8c1ce514b2a1d0edf558f2e69bf704d0fa6d2bd4 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Thu, 9 Mar 2023 22:34:46 +0900 Subject: [PATCH 3/4] fix style --- Library/Homebrew/cask/uninstall.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/cask/uninstall.rb b/Library/Homebrew/cask/uninstall.rb index 0e9522b8e6..31cc6d54b6 100644 --- a/Library/Homebrew/cask/uninstall.rb +++ b/Library/Homebrew/cask/uninstall.rb @@ -4,7 +4,6 @@ module Cask # @api private class Uninstall - def self.uninstall_casks(*casks, binaries: nil, force: false, verbose: false) require "cask/installer" From e321edabbc6bd8b6f36e31bc0d20681ac91f593f Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Sat, 11 Mar 2023 21:15:24 +0900 Subject: [PATCH 4/4] remove options and comments --- Library/Homebrew/cask/uninstall.rb | 8 +------- Library/Homebrew/test/cask/uninstall_spec.rb | 2 -- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/uninstall.rb b/Library/Homebrew/cask/uninstall.rb index 31cc6d54b6..71b3684a00 100644 --- a/Library/Homebrew/cask/uninstall.rb +++ b/Library/Homebrew/cask/uninstall.rb @@ -7,18 +7,12 @@ module Cask def self.uninstall_casks(*casks, binaries: nil, force: false, verbose: false) require "cask/installer" - options = { - binaries: binaries, - force: force, - verbose: verbose, - }.compact - casks.each do |cask| odebug "Uninstalling Cask #{cask}" raise CaskNotInstalledError, cask if !cask.installed? && !force - Installer.new(cask, **options).uninstall + Installer.new(cask, binaries: binaries, force: force, verbose: verbose).uninstall next if (versions = cask.versions).empty? diff --git a/Library/Homebrew/test/cask/uninstall_spec.rb b/Library/Homebrew/test/cask/uninstall_spec.rb index 0d3340f883..b7f712c4fd 100644 --- a/Library/Homebrew/test/cask/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/uninstall_spec.rb @@ -86,7 +86,6 @@ describe Cask::Uninstall, :cask do ] end let(:caskroom_path) { Cask::Caskroom.path.join(token).tap(&:mkpath) } - # let(:versioned_cask) { Cask::CaskLoader.load(caskroom_path) } before do timestamped_versions.each do |timestamped_version| @@ -127,7 +126,6 @@ describe Cask::Uninstall, :cask do context "when Casks in Taps have been renamed or removed" do let(:app) { Cask::Config.new.appdir.join("ive-been-renamed.app") } let(:caskroom_path) { Cask::Caskroom.path.join("ive-been-renamed").tap(&:mkpath) } - # let(:ive_been_renamed) { Cask::CaskLoader.load(caskroom_path) } let(:saved_caskfile) do caskroom_path.join(".metadata", "latest", "timestamp", "Casks").join("ive-been-renamed.rb") end