| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-16 11:15:54 -05:00
										 |  |  | class Caveats | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  |   undef plist_caveats | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-16 11:15:54 -05:00
										 |  |  |   def plist_caveats | 
					
						
							|  |  |  |     s = [] | 
					
						
							| 
									
										
										
										
											2021-05-04 14:36:00 +02:00
										 |  |  |     return if !f.plist && !f.service? && !keg&.plist_installed? | 
					
						
							| 
									
										
										
										
											2021-05-01 16:05:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     plist_domain = f.plist_path.basename(".plist") | 
					
						
							| 
									
										
										
										
											2017-10-16 11:15:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-01 16:05:25 +02:00
										 |  |  |     # we readlink because this path probably doesn't exist since caveats | 
					
						
							|  |  |  |     # occurs before the link step of installation | 
					
						
							|  |  |  |     # Yosemite security measures mildly tighter rules: | 
					
						
							|  |  |  |     # https://github.com/Homebrew/legacy-homebrew/issues/33815 | 
					
						
							|  |  |  |     if f.plist && (!plist_path.file? || !plist_path.symlink?) | 
					
						
							|  |  |  |       if f.plist_startup | 
					
						
							|  |  |  |         s << "To have launchd start #{f.full_name} now and restart at startup:" | 
					
						
							|  |  |  |         s << "  sudo brew services start #{f.full_name}" | 
					
						
							| 
									
										
										
										
											2017-10-16 11:15:54 -05:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2021-05-01 16:05:25 +02:00
										 |  |  |         s << "To have launchd start #{f.full_name} now and restart at login:" | 
					
						
							| 
									
										
										
										
											2017-10-16 11:15:54 -05:00
										 |  |  |         s << "  brew services start #{f.full_name}" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-05-01 16:05:25 +02:00
										 |  |  |     # For startup plists, we cannot tell whether it's running on launchd, | 
					
						
							|  |  |  |     # as it requires for `sudo launchctl list` to get real result. | 
					
						
							|  |  |  |     elsif f.plist_startup | 
					
						
							|  |  |  |       s << "To restart #{f.full_name} after an upgrade:" | 
					
						
							|  |  |  |       s << "  sudo brew services restart #{f.full_name}" | 
					
						
							|  |  |  |     elsif Kernel.system "/bin/launchctl list #{plist_domain} &>/dev/null" | 
					
						
							|  |  |  |       s << "To restart #{f.full_name} after an upgrade:" | 
					
						
							|  |  |  |       s << "  brew services restart #{f.full_name}" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       s << "To start #{f.full_name}:" | 
					
						
							|  |  |  |       s << "  brew services start #{f.full_name}" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-16 11:15:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-01 16:05:25 +02:00
										 |  |  |     if f.plist_manual || f.service? | 
					
						
							|  |  |  |       command = if f.service? | 
					
						
							| 
									
										
										
										
											2021-09-07 10:10:26 -06:00
										 |  |  |         f.service | 
					
						
							|  |  |  |          .command | 
					
						
							|  |  |  |          .map do |arg| | 
					
						
							|  |  |  |            next arg unless arg.match?(/\s/) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            # quote multi-word arguments | 
					
						
							|  |  |  |            "'#{arg}'" | 
					
						
							|  |  |  |          end.join(" ") | 
					
						
							| 
									
										
										
										
											2021-05-01 16:05:25 +02:00
										 |  |  |       else | 
					
						
							|  |  |  |         f.plist_manual | 
					
						
							| 
									
										
										
										
											2017-10-16 11:15:54 -05:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-01 16:05:25 +02:00
										 |  |  |       s << "Or, if you don't want/need a background service you can just run:" | 
					
						
							|  |  |  |       s << "  #{command}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # pbpaste is the system clipboard tool on macOS and fails with `tmux` by default | 
					
						
							|  |  |  |     # check if this is being run under `tmux` to avoid failing | 
					
						
							| 
									
										
										
										
											2021-05-13 17:05:18 +01:00
										 |  |  |     if ENV["HOMEBREW_TMUX"] && !quiet_system("/usr/bin/pbpaste") | 
					
						
							| 
									
										
										
										
											2021-05-01 16:05:25 +02:00
										 |  |  |       s << "" << "WARNING: brew services will fail when run under tmux." | 
					
						
							| 
									
										
										
										
											2017-10-16 11:15:54 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-19 17:12:32 +01:00
										 |  |  |     "#{s.join("\n")}\n" unless s.empty? | 
					
						
							| 
									
										
										
										
											2017-10-16 11:15:54 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | end |