Skip to content

Commit cb17a80

Browse files
authored
Merge pull request #2362 from joshka/install-uninstall-messages
Install uninstall messages
2 parents 64e2e6e + cb28ab6 commit cb17a80

File tree

5 files changed

+81
-26
lines changed

5 files changed

+81
-26
lines changed

Library/Homebrew/cask/lib/hbc/cli/reinstall.rb

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,10 @@ def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
77
begin
88
cask = CaskLoader.load(cask_token)
99

10-
installer = Installer.new(cask,
11-
force: force,
12-
skip_cask_deps: skip_cask_deps,
13-
require_sha: require_sha)
14-
installer.print_caveats
15-
installer.fetch
16-
17-
if cask.installed?
18-
# use copy of cask for uninstallation to avoid 'No such file or directory' bug
19-
installed_cask = cask
20-
21-
# use the same cask file that was used for installation, if possible
22-
if (installed_caskfile = installed_cask.installed_caskfile).exist?
23-
installed_cask = CaskLoader.load_from_file(installed_caskfile)
24-
end
25-
26-
# Always force uninstallation, ignore method parameter
27-
Installer.new(installed_cask, force: true).uninstall
28-
end
29-
30-
installer.stage
31-
installer.install_artifacts
32-
installer.enable_accessibility_access
33-
puts installer.summary
10+
Installer.new(cask,
11+
force: force,
12+
skip_cask_deps: skip_cask_deps,
13+
require_sha: require_sha).reinstall
3414

3515
count += 1
3616
rescue CaskUnavailableError => e

Library/Homebrew/cask/lib/hbc/installer.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false
2424
@force = force
2525
@skip_cask_deps = skip_cask_deps
2626
@require_sha = require_sha
27+
@reinstall = false
2728
end
2829

2930
def self.print_caveats(cask)
@@ -76,20 +77,40 @@ def stage
7677
def install
7778
odebug "Hbc::Installer#install"
7879

79-
if @cask.installed? && !force
80+
if @cask.installed? && !force && !@reinstall
8081
raise CaskAlreadyInstalledAutoUpdatesError, @cask if @cask.auto_updates
8182
raise CaskAlreadyInstalledError, @cask
8283
end
8384

8485
print_caveats
8586
fetch
87+
uninstall_existing_cask if @reinstall
88+
89+
oh1 "Installing Cask #{@cask}"
8690
stage
8791
install_artifacts
8892
enable_accessibility_access
8993

9094
puts summary
9195
end
9296

97+
def reinstall
98+
odebug "Hbc::Installer#reinstall"
99+
@reinstall = true
100+
install
101+
end
102+
103+
def uninstall_existing_cask
104+
return unless @cask.installed?
105+
106+
# use the same cask file that was used for installation, if possible
107+
installed_caskfile = @cask.installed_caskfile
108+
installed_cask = installed_caskfile.exist? ? CaskLoader.load_from_file(installed_caskfile) : @cask
109+
110+
# Always force uninstallation, ignore method parameter
111+
Installer.new(installed_cask, force: true).uninstall
112+
end
113+
93114
def summary
94115
s = ""
95116
s << "#{Emoji.install_badge} " if Emoji.enabled?
@@ -305,7 +326,7 @@ def save_caskfile
305326
end
306327

307328
def uninstall
308-
odebug "Hbc::Installer#uninstall"
329+
oh1 "Uninstalling Cask #{@cask}"
309330
disable_accessibility_access
310331
uninstall_artifacts
311332
purge_versioned_files

Library/Homebrew/test/cask/cli/install_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
describe Hbc::CLI::Install, :cask do
2+
it "displays the installation progress" do
3+
output = Regexp.new <<-EOS.undent
4+
==> Downloading file:.*caffeine.zip
5+
==> Verifying checksum for Cask local-caffeine
6+
==> Installing Cask local-caffeine
7+
==> Moving App 'Caffeine.app' to '.*Caffeine.app'.
8+
.*local-caffeine was successfully installed!
9+
EOS
10+
11+
expect {
12+
Hbc::CLI::Install.run("local-caffeine")
13+
}.to output(output).to_stdout
14+
end
15+
216
it "allows staging and activation of multiple Casks at once" do
317
shutup do
418
Hbc::CLI::Install.run("local-transmission", "local-caffeine")

Library/Homebrew/test/cask/cli/reinstall_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
describe Hbc::CLI::Reinstall, :cask do
2+
it "displays the reinstallation progress" do
3+
caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
4+
5+
shutup do
6+
Hbc::Installer.new(caffeine).install
7+
end
8+
9+
output = Regexp.new <<-EOS.undent
10+
==> Downloading file:.*caffeine.zip
11+
Already downloaded: .*local-caffeine--1.2.3.zip
12+
==> Verifying checksum for Cask local-caffeine
13+
==> Uninstalling Cask local-caffeine
14+
==> Removing App '.*Caffeine.app'.
15+
==> Installing Cask local-caffeine
16+
==> Moving App 'Caffeine.app' to '.*Caffeine.app'.
17+
.*local-caffeine was successfully installed!
18+
EOS
19+
20+
expect {
21+
Hbc::CLI::Reinstall.run("local-caffeine")
22+
}.to output(output).to_stdout
23+
end
24+
225
it "allows reinstalling a Cask" do
326
shutup do
427
Hbc::CLI::Install.run("local-transmission")

Library/Homebrew/test/cask/cli/uninstall_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
describe Hbc::CLI::Uninstall, :cask do
2+
it "displays the uninstallation progress" do
3+
caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
4+
5+
shutup do
6+
Hbc::Installer.new(caffeine).install
7+
end
8+
9+
output = Regexp.new <<-EOS.undent
10+
==> Uninstalling Cask local-caffeine
11+
==> Removing App '.*Caffeine.app'.
12+
EOS
13+
14+
expect {
15+
Hbc::CLI::Uninstall.run("local-caffeine")
16+
}.to output(output).to_stdout
17+
end
18+
219
it "shows an error when a bad Cask is provided" do
320
expect {
421
Hbc::CLI::Uninstall.run("notacask")

0 commit comments

Comments
 (0)