| 
									
										
										
										
											2023-12-13 13:54:37 +00:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2018-11-11 18:35:55 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											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 18:35:55 +05:30
										 |  |  |   def untap_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2019-08-19 22:44:50 -04:00
										 |  |  |         Remove a tapped formula repository. | 
					
						
							| 
									
										
										
										
											2018-11-11 18:35:55 +05:30
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2021-02-04 18:36:32 +01:00
										 |  |  |       switch "-f", "--force", | 
					
						
							|  |  |  |              description: "Untap even if formulae or casks from this tap are currently installed." | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  |       named_args :tap, min: 1
 | 
					
						
							| 
									
										
										
										
											2018-11-11 18:35:55 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-13 13:54:37 +00:00
										 |  |  |   sig { void } | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  |   def untap | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     args = untap_args.parse | 
					
						
							| 
									
										
										
										
											2018-11-11 18:35:55 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  |     args.named.to_installed_taps.each do |tap| | 
					
						
							| 
									
										
										
										
											2023-02-24 13:25:18 +00:00
										 |  |  |       odie "Untapping #{tap} is not allowed" if tap.core_tap? && Homebrew::EnvConfig.no_install_from_api? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-13 13:54:37 +00:00
										 |  |  |       if Homebrew::EnvConfig.no_install_from_api? || (!tap.core_tap? && !tap.core_cask_tap?) | 
					
						
							|  |  |  |         installed_formula_names = T.let(nil, T.nilable(T::Set[String])) | 
					
						
							|  |  |  |         installed_tap_formulae = tap.formula_names.map do |formula_name| | 
					
						
							|  |  |  |           # initialise lazily in case there's no formulae in this tap | 
					
						
							|  |  |  |           installed_formula_names ||= Set.new(Formula.installed_formula_names) | 
					
						
							|  |  |  |           next unless installed_formula_names.include?(formula_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           formula = begin | 
					
						
							|  |  |  |             Formulary.factory("#{tap.name}/#{formula_name}") | 
					
						
							|  |  |  |           rescue | 
					
						
							|  |  |  |             # Don't blow up because of a single unavailable formula. | 
					
						
							|  |  |  |             next | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-13 15:24:37 +00:00
										 |  |  |           # Can't use Formula#any_version_installed? because it doesn't consider | 
					
						
							|  |  |  |           # taps correctly. | 
					
						
							|  |  |  |           formula if formula.installed_kegs.any? { |keg| keg.tab.tap == tap } | 
					
						
							| 
									
										
										
										
											2023-12-13 13:54:37 +00:00
										 |  |  |         end.compact | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         installed_cask_tokens = T.let(nil, T.nilable(T::Set[String])) | 
					
						
							|  |  |  |         installed_tap_casks = tap.cask_tokens.map do |cask_token| | 
					
						
							|  |  |  |           # initialise lazily in case there's no casks in this tap | 
					
						
							|  |  |  |           installed_cask_tokens ||= Set.new(Cask::Caskroom.tokens) | 
					
						
							|  |  |  |           next unless installed_cask_tokens.include?(cask_token) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           cask = begin | 
					
						
							|  |  |  |             Cask::CaskLoader.load("#{tap.name}/#{cask_token}") | 
					
						
							|  |  |  |           rescue | 
					
						
							|  |  |  |             # Don't blow up because of a single unavailable cask. | 
					
						
							|  |  |  |             next | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           cask if cask.installed? | 
					
						
							|  |  |  |         end.compact | 
					
						
							| 
									
										
										
										
											2021-10-28 17:13:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if installed_tap_formulae.present? || installed_tap_casks.present? | 
					
						
							|  |  |  |           installed_names = (installed_tap_formulae + installed_tap_casks.map(&:token)).join("\n") | 
					
						
							|  |  |  |           if args.force? || Homebrew::EnvConfig.developer? | 
					
						
							|  |  |  |             opoo <<~EOS | 
					
						
							|  |  |  |               Untapping #{tap} even though it contains the following installed formulae or casks: | 
					
						
							|  |  |  |               #{installed_names} | 
					
						
							|  |  |  |             EOS | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             odie <<~EOS | 
					
						
							|  |  |  |               Refusing to untap #{tap} because it contains the following installed formulae or casks: | 
					
						
							|  |  |  |               #{installed_names} | 
					
						
							|  |  |  |             EOS | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2020-12-04 21:19:48 +01:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-21 08:42:22 -05:00
										 |  |  |       tap.uninstall manual: true | 
					
						
							| 
									
										
										
										
											2015-02-01 12:11:54 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-03-18 00:40:41 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-03-02 20:28:54 +00:00
										 |  |  | end |