 94148c3bc8
			
		
	
	
		94148c3bc8
		
			
		
	
	
	
	
		
			
			When casks are unreadable (e.g. have invalid syntax, the cask file cannot be found) then it's not been possible to uninstall them, list them or perform any operation which iterates through all casks. Handle these various cases by falling back to creating a `Cask::Cask` object using just the name/token and latest installed version on disk. This provides enough functionality to be able to verbosely list these casks, not error on listing and, most importantly, uninstall/reinstall them. Fixes https://github.com/Homebrew/homebrew-cask/issues/62223
		
			
				
	
	
		
			57 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # typed: false
 | |
| # frozen_string_literal: true
 | |
| 
 | |
| module Cask
 | |
|   class Cmd
 | |
|     # Cask implementation of the `brew uninstall` command.
 | |
|     #
 | |
|     # @api private
 | |
|     class Uninstall < AbstractCommand
 | |
|       extend T::Sig
 | |
| 
 | |
|       def self.parser
 | |
|         super do
 | |
|           switch "--force",
 | |
|                  description: "Uninstall even if the <cask> is not installed, overwrite " \
 | |
|                               "existing files and ignore errors when removing files."
 | |
|         end
 | |
|       end
 | |
| 
 | |
|       sig { void }
 | |
|       def run
 | |
|         self.class.uninstall_casks(
 | |
|           *casks,
 | |
|           binaries: args.binaries?,
 | |
|           verbose:  args.verbose?,
 | |
|           force:    args.force?,
 | |
|         )
 | |
|       end
 | |
| 
 | |
|       def self.uninstall_casks(*casks, binaries: nil, force: false, verbose: false)
 | |
|         require "cask/installer"
 | |
| 
 | |
|         options = {
 | |
|           binaries: binaries,
 | |
|           force:    force,
 | |
|           verbose:  verbose,
 | |
|         }.compact
 | |
| 
 | |
|         casks.each do |cask|
 | |
|           odebug "Uninstalling Cask #{cask}"
 | |
| 
 | |
|           raise CaskNotInstalledError, cask if !cask.installed? && !force
 | |
| 
 | |
|           Installer.new(cask, **options).uninstall
 | |
| 
 | |
|           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 uninstall --cask --force #{cask}`.
 | |
|           EOS
 | |
|         end
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| end
 |