From 3678a107e852acdecb084e913bb643c406f97d93 Mon Sep 17 00:00:00 2001 From: Ben Creasy Date: Tue, 23 Jun 2015 12:12:10 -0700 Subject: [PATCH] New exception if uninstall fails but cask is installed --- lib/hbc/cask.rb | 4 ++++ lib/hbc/cli/uninstall.rb | 8 +++++++- lib/hbc/exceptions.rb | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/hbc/cask.rb b/lib/hbc/cask.rb index 2fb8ccbb2eb6..879f03bd3337 100644 --- a/lib/hbc/cask.rb +++ b/lib/hbc/cask.rb @@ -75,6 +75,10 @@ def installed? staged_path.exist? end + def installed_at_all? + caskroom_path.exist? + end + def to_s @token end diff --git a/lib/hbc/cli/uninstall.rb b/lib/hbc/cli/uninstall.rb index bef08b2ad72b..46c0bd5abae2 100644 --- a/lib/hbc/cli/uninstall.rb +++ b/lib/hbc/cli/uninstall.rb @@ -6,7 +6,13 @@ def self.run(*args) cask_tokens.each do |cask_token| odebug "Uninstalling Cask #{cask_token}" cask = Hbc.load(cask_token) - raise Hbc::CaskNotInstalledError.new(cask) unless cask.installed? or force + if !cask.installed? and !force + if cask.installed_at_all? + raise Hbc::CaskUninstallVersionError.new(cask) + else + raise Hbc::CaskNotInstalledError.new(cask) + end + end Hbc::Installer.new(cask).uninstall(force) end end diff --git a/lib/hbc/exceptions.rb b/lib/hbc/exceptions.rb index ae7e3c7a468c..6e2aef01c143 100644 --- a/lib/hbc/exceptions.rb +++ b/lib/hbc/exceptions.rb @@ -11,6 +11,17 @@ def to_s end end +class Hbc::CaskUninstallVersionError < Hbc::CaskError + attr_reader :token + def initialize(token) + @token = token + end + + def to_s + "#{token} has an updated version, use uninstall --force to remove" + end +end + class Hbc::CaskUnavailableError < Hbc::CaskError attr_reader :token def initialize(token)