uninstall: Refactor to use AbstractCommand instead of declaring a class method

This commit is contained in:
William Ma 2020-06-24 15:08:42 -04:00
parent d1004c8143
commit e733fa16a2
2 changed files with 21 additions and 23 deletions

View File

@ -12,29 +12,25 @@ module Cask
def run
casks.each do |cask|
self.class.uninstall_cask cask, binaries?, verbose?, force?
end
end
def self.uninstall_cask(cask, binaries, verbose, force)
odebug "Uninstalling Cask #{cask}"
raise CaskNotInstalledError, cask unless cask.installed? || force
raise CaskNotInstalledError, cask unless cask.installed? || force?
if cask.installed? && !cask.installed_caskfile.nil?
# use the same cask file that was used for installation, if possible
cask = CaskLoader.load(cask.installed_caskfile) if cask.installed_caskfile.exist?
end
Installer.new(cask, binaries: binaries, verbose: verbose, force: force).uninstall
Installer.new(cask, binaries: binaries?, verbose: verbose?, force: force?).uninstall
return if (versions = cask.versions).empty?
next if (versions = cask.versions).empty?
puts <<~EOS
#{cask} #{versions.to_sentence} #{"is".pluralize(versions.count)} still installed.
Remove #{(versions.count == 1) ? "it" : "them all"} with `brew cask uninstall --force #{cask}`.
EOS
end
end
def self.help
"uninstalls the given Cask"

View File

@ -119,8 +119,10 @@ module Homebrew
end
possible_casks.each do |name|
cask = Cask::CaskLoader.load name
Cask::Cmd::Uninstall.uninstall_cask(cask, true, args.verbose, args.force?)
cmd = Cask::Cmd::Uninstall.new(name)
cmd.force = args.force?
cmd.verbose = args.verbose?
cmd.run
rescue Cask::CaskUnavailableError
ofail "No installed keg or cask with the name \"#{name}\""
end