From 082bd5e98ae7592bc92466186609066e00c2bf84 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 1 Oct 2016 23:18:13 +0200 Subject: [PATCH 1/4] Change `A Cask for #{token} is already installed.` message. --- Library/Homebrew/cask/lib/hbc/cli/install.rb | 2 +- Library/Homebrew/cask/lib/hbc/exceptions.rb | 23 ++++++++++++++++--- Library/Homebrew/cask/lib/hbc/installer.rb | 7 +++--- .../Homebrew/cask/test/cask/installer_test.rb | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb index d7575344db..996de8d1b5 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/install.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb @@ -27,7 +27,7 @@ module Hbc rescue CaskAlreadyInstalledError => e opoo e.message count += 1 - rescue CaskAutoUpdatesError => e + rescue CaskAlreadyInstalledAutoUpdatesError => e opoo e.message count += 1 rescue CaskUnavailableError => e diff --git a/Library/Homebrew/cask/lib/hbc/exceptions.rb b/Library/Homebrew/cask/lib/hbc/exceptions.rb index f77106d924..2f63366cad 100644 --- a/Library/Homebrew/cask/lib/hbc/exceptions.rb +++ b/Library/Homebrew/cask/lib/hbc/exceptions.rb @@ -29,13 +29,30 @@ module Hbc class CaskAlreadyInstalledError < AbstractCaskErrorWithToken def to_s - %Q{A Cask for #{token} is already installed. Add the "--force" option to force re-install.} + s = <<-EOS.undent + A Cask for #{token} is already installed. + EOS + + s.concat("\n").concat(reinstall_message) + end + + private + + def reinstall_message + <<-EOS.undent + To re-install #{token}, run: + brew cask uninstall --force #{token}; brew cask install #{token} + EOS end end - class CaskAutoUpdatesError < AbstractCaskErrorWithToken + class CaskAlreadyInstalledAutoUpdatesError < CaskAlreadyInstalledError def to_s - %Q{A Cask for #{token} is already installed and using auto-updates. Add the "--force" option to force re-install.} + s = <<-EOS.undent + A Cask for #{token} is already installed and using auto-updates. + EOS + + s.concat("\n").concat(reinstall_message) end end diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 4d29acb752..9575aa1814 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -58,12 +58,11 @@ module Hbc def install odebug "Hbc::Installer.install" - if @cask.installed? && @cask.auto_updates && !force - raise CaskAutoUpdatesError, @cask + if @cask.installed? && !force + raise CaskAlreadyInstalledAutoUpdatesError, @cask if @cask.auto_updates + raise CaskAlreadyInstalledError, @cask end - raise CaskAlreadyInstalledError, @cask if @cask.installed? && !force - print_caveats begin diff --git a/Library/Homebrew/cask/test/cask/installer_test.rb b/Library/Homebrew/cask/test/cask/installer_test.rb index 2275c30801..64a0e9b878 100644 --- a/Library/Homebrew/cask/test/cask/installer_test.rb +++ b/Library/Homebrew/cask/test/cask/installer_test.rb @@ -272,7 +272,7 @@ describe Hbc::Installer do lambda { installer.install - }.must_raise(Hbc::CaskAutoUpdatesError) + }.must_raise(Hbc::CaskAlreadyInstalledAutoUpdatesError) end it "allows already-installed Casks which auto-update to be installed if force is provided" do From 4f1ef16cbf09fc1b98143ff672859dcefda00e1b Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 1 Oct 2016 23:18:38 +0200 Subject: [PATCH 2/4] Fix indentation of CaskCommandFailedError. --- Library/Homebrew/cask/lib/hbc/exceptions.rb | 28 ++++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/exceptions.rb b/Library/Homebrew/cask/lib/hbc/exceptions.rb index 2f63366cad..0977ac5c92 100644 --- a/Library/Homebrew/cask/lib/hbc/exceptions.rb +++ b/Library/Homebrew/cask/lib/hbc/exceptions.rb @@ -65,21 +65,19 @@ module Hbc end def to_s - <<-EOS - Command failed to execute! - - ==> Failed command: - #{@cmd} - - ==> Standard Output of failed command: - #{@stdout} - - ==> Standard Error of failed command: - #{@stderr} - - ==> Exit status of failed command: - #{@status.inspect} - EOS + s = "Command failed to execute!\n" + s.concat("\n") + s.concat("==> Failed command:\n") + s.concat(@cmd).concat("\n") + s.concat("\n") + s.concat("==> Standard Output of failed command:\n") + s.concat(@stdout).concat("\n") + s.concat("\n") + s.concat("==> Standard Error of failed command:\n") + s.concat(@stderr).concat("\n") + s.concat("\n") + s.concat("==> Exit status of failed command:\n") + s.concat(@status.inspect).concat("\n") end end From e4da2dfb9f49349251b51e80be57d2a70c979321 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 1 Oct 2016 23:27:14 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Make=20test=20for=20=E2=80=9Ccask=20already?= =?UTF-8?q?=20installed=E2=80=9D=20less=20strict.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/cask/test/cask/cli/install_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/test/cask/cli/install_test.rb b/Library/Homebrew/cask/test/cask/cli/install_test.rb index 2d09846b7f..138c497fbd 100644 --- a/Library/Homebrew/cask/test/cask/cli/install_test.rb +++ b/Library/Homebrew/cask/test/cask/cli/install_test.rb @@ -29,7 +29,7 @@ describe Hbc::CLI::Install do TestHelper.must_output(self, lambda { Hbc::CLI::Install.run("local-transmission", "") - }, %r{Warning: A Cask for local-transmission is already installed. Add the "--force" option to force re-install.}) + }, %r{Warning: A Cask for local-transmission is already installed.}) end it "allows double install with --force" do From 0f7d1b137f55264366c772105e5026253906d896 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 2 Oct 2016 19:53:34 +0200 Subject: [PATCH 4/4] Change re-install command to use `&&`. --- Library/Homebrew/cask/lib/hbc/exceptions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/exceptions.rb b/Library/Homebrew/cask/lib/hbc/exceptions.rb index 0977ac5c92..8c9481eec7 100644 --- a/Library/Homebrew/cask/lib/hbc/exceptions.rb +++ b/Library/Homebrew/cask/lib/hbc/exceptions.rb @@ -41,7 +41,7 @@ module Hbc def reinstall_message <<-EOS.undent To re-install #{token}, run: - brew cask uninstall --force #{token}; brew cask install #{token} + brew cask uninstall --force #{token} && brew cask install #{token} EOS end end