| 
									
										
										
										
											2020-11-19 12:57:10 +01:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "keg" | 
					
						
							|  |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2016-09-30 19:34:14 +01:00
										 |  |  | require "diagnostic" | 
					
						
							| 
									
										
										
										
											2015-08-09 14:57:15 +03:00
										 |  |  | require "migrator" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2020-06-24 11:59:55 -04:00
										 |  |  | require "cask/cask_loader" | 
					
						
							| 
									
										
										
										
											2023-03-02 22:29:57 +09:00
										 |  |  | require "cask/exceptions" | 
					
						
							|  |  |  | require "cask/installer" | 
					
						
							| 
									
										
										
										
											2023-03-09 22:33:29 +09:00
										 |  |  | require "cask/uninstall" | 
					
						
							| 
									
										
										
										
											2020-11-01 14:45:11 -05:00
										 |  |  | require "uninstall" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2018-11-11 17:43:31 +05:30
										 |  |  |   def uninstall_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2020-11-19 12:57:10 +01:00
										 |  |  |         Uninstall a <formula> or <cask>. | 
					
						
							| 
									
										
										
										
											2018-11-11 17:43:31 +05:30
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2020-07-27 03:59:52 +02:00
										 |  |  |       switch "-f", "--force", | 
					
						
							| 
									
										
										
										
											2020-11-19 12:57:10 +01:00
										 |  |  |              description: "Delete all installed versions of <formula>. Uninstall even if <cask> is not " \ | 
					
						
							|  |  |  |                           "installed, overwrite existing files and ignore errors when removing files." | 
					
						
							| 
									
										
										
										
											2020-11-19 14:02:28 +01:00
										 |  |  |       switch "--zap", | 
					
						
							|  |  |  |              description: "Remove all files associated with a <cask>. " \ | 
					
						
							|  |  |  |                           "*May remove files which are shared between applications.*" | 
					
						
							| 
									
										
										
										
											2018-11-11 17:43:31 +05:30
										 |  |  |       switch "--ignore-dependencies", | 
					
						
							| 
									
										
										
										
											2022-06-28 10:09:59 +01:00
										 |  |  |              description: "Don't fail uninstall, even if <formula> is a dependency of any installed " \ | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |                           "formulae." | 
					
						
							| 
									
										
										
										
											2020-11-18 16:39:07 +01:00
										 |  |  |       switch "--formula", "--formulae", | 
					
						
							|  |  |  |              description: "Treat all named arguments as formulae." | 
					
						
							|  |  |  |       switch "--cask", "--casks", | 
					
						
							|  |  |  |              description: "Treat all named arguments as casks." | 
					
						
							| 
									
										
										
										
											2020-11-27 11:41:08 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-18 16:39:07 +01:00
										 |  |  |       conflicts "--formula", "--cask" | 
					
						
							| 
									
										
										
										
											2020-11-27 11:41:08 -05:00
										 |  |  |       conflicts "--formula", "--zap" | 
					
						
							| 
									
										
										
										
											2020-11-18 16:39:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  |       named_args [:installed_formula, :installed_cask], min: 1
 | 
					
						
							| 
									
										
										
										
											2018-11-11 17:43:31 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def uninstall | 
					
						
							| 
									
										
										
										
											2020-07-26 09:45:26 +02:00
										 |  |  |     args = uninstall_args.parse | 
					
						
							| 
									
										
										
										
											2018-11-11 17:43:31 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-15 23:43:46 +09:00
										 |  |  |     all_kegs, casks = args.named.to_kegs_to_casks( | 
					
						
							|  |  |  |       ignore_unavailable: args.force?, | 
					
						
							|  |  |  |       all_kegs:           args.force?, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-11-18 16:39:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-08 10:21:57 -07:00
										 |  |  |     # If ignore_unavailable is true and the named args | 
					
						
							|  |  |  |     # are a series of invalid kegs and casks, | 
					
						
							|  |  |  |     # #to_kegs_to_casks will return empty arrays. | 
					
						
							|  |  |  |     return if all_kegs.blank? && casks.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 12:57:10 +01:00
										 |  |  |     kegs_by_rack = all_kegs.group_by(&:rack) | 
					
						
							| 
									
										
										
										
											2020-07-02 15:28:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 12:57:10 +01:00
										 |  |  |     Uninstall.uninstall_kegs( | 
					
						
							|  |  |  |       kegs_by_rack, | 
					
						
							| 
									
										
										
										
											2021-02-09 06:11:53 +05:30
										 |  |  |       casks:               casks, | 
					
						
							| 
									
										
										
										
											2020-11-19 12:57:10 +01:00
										 |  |  |       force:               args.force?, | 
					
						
							|  |  |  |       ignore_dependencies: args.ignore_dependencies?, | 
					
						
							|  |  |  |       named_args:          args.named, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-06-30 13:43:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 14:02:28 +01:00
										 |  |  |     if args.zap? | 
					
						
							| 
									
										
										
										
											2023-03-02 22:29:57 +09:00
										 |  |  |       casks.each do |cask| | 
					
						
							|  |  |  |         odebug "Zapping Cask #{cask}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         raise Cask::CaskNotInstalledError, cask if !cask.installed? && !args.force? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Cask::Installer.new(cask, verbose: args.verbose?, force: args.force?).zap | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-11-19 14:02:28 +01:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2023-03-09 22:33:29 +09:00
										 |  |  |       Cask::Uninstall.uninstall_casks( | 
					
						
							| 
									
										
										
										
											2020-11-19 14:02:28 +01:00
										 |  |  |         *casks, | 
					
						
							| 
									
										
										
										
											2021-02-22 19:43:30 -08:00
										 |  |  |         verbose: args.verbose?, | 
					
						
							|  |  |  |         force:   args.force?, | 
					
						
							| 
									
										
										
										
											2020-11-19 14:02:28 +01:00
										 |  |  |       ) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2022-07-08 10:21:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-14 13:16:26 -07:00
										 |  |  |     Cleanup.autoremove if Homebrew::EnvConfig.autoremove? | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |