| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-05 17:17:03 -05:00
										 |  |  | # A {Messages} object collects messages that may need to be displayed together | 
					
						
							| 
									
										
										
										
											2018-10-18 21:42:43 -04:00
										 |  |  | # at the end of a multi-step `brew` command run. | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  | class Messages | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-02 08:42:48 -07:00
										 |  |  |   attr_reader :caveats, :package_count, :install_times | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { void } | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |   def initialize | 
					
						
							|  |  |  |     @caveats = [] | 
					
						
							| 
									
										
										
										
											2021-09-02 08:42:48 -07:00
										 |  |  |     @package_count = 0
 | 
					
						
							| 
									
										
										
										
											2018-06-20 00:54:14 -04:00
										 |  |  |     @install_times = [] | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-08 23:43:14 +01:00
										 |  |  |   def record_caveats(package, caveats) | 
					
						
							|  |  |  |     @caveats.push(package: package, caveats: caveats) | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-02 08:42:48 -07:00
										 |  |  |   def package_installed(package, elapsed_time) | 
					
						
							|  |  |  |     @package_count += 1
 | 
					
						
							|  |  |  |     @install_times.push(package: package, time: elapsed_time) | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 11:43:11 -08:00
										 |  |  |   def display_messages(force_caveats: false, display_times: false) | 
					
						
							|  |  |  |     display_caveats(force: force_caveats) | 
					
						
							| 
									
										
										
										
											2020-07-25 21:33:48 +02:00
										 |  |  |     display_install_times if display_times | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-11 11:43:11 -08:00
										 |  |  |   def display_caveats(force: false) | 
					
						
							| 
									
										
										
										
											2021-09-02 08:42:48 -07:00
										 |  |  |     return if @package_count.zero? | 
					
						
							|  |  |  |     return if @package_count == 1 && !force | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |     return if @caveats.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |     oh1 "Caveats" | 
					
						
							|  |  |  |     @caveats.each do |c| | 
					
						
							| 
									
										
										
										
											2021-06-08 23:43:14 +01:00
										 |  |  |       ohai c[:package], c[:caveats] | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-06-20 00:54:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def display_install_times | 
					
						
							|  |  |  |     return if install_times.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-20 00:54:14 -04:00
										 |  |  |     oh1 "Installation times" | 
					
						
							|  |  |  |     install_times.each do |t| | 
					
						
							| 
									
										
										
										
											2021-09-02 08:42:48 -07:00
										 |  |  |       puts format("%<package>-20s %<time>10.3f s", t) | 
					
						
							| 
									
										
										
										
											2018-06-20 00:54:14 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  | end |