Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New exception if uninstall fails but cask is installed #12076

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/hbc/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def installed?
staged_path.exist?
end

def installed_at_all?
caskroom_path.exist?
end

def to_s
@token
end
Expand Down
8 changes: 7 additions & 1 deletion lib/hbc/cli/uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lib/hbc/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down