| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04: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 | 
					
						
							| 
									
										
										
										
											2018-06-20 00:54:14 -04:00
										 |  |  |   attr_reader :caveats, :formula_count, :install_times | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def initialize | 
					
						
							|  |  |  |     @caveats = [] | 
					
						
							|  |  |  |     @formula_count = 0
 | 
					
						
							| 
									
										
										
										
											2018-06-20 00:54:14 -04:00
										 |  |  |     @install_times = [] | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def record_caveats(f, caveats) | 
					
						
							|  |  |  |     @caveats.push(formula: f.name, caveats: caveats) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-20 00:54:14 -04:00
										 |  |  |   def formula_installed(f, elapsed_time) | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |     @formula_count += 1
 | 
					
						
							| 
									
										
										
										
											2018-06-20 00:54:14 -04:00
										 |  |  |     @install_times.push(formula: f.name, time: elapsed_time) | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def display_messages | 
					
						
							|  |  |  |     display_caveats | 
					
						
							| 
									
										
										
										
											2019-07-28 11:12:32 +01:00
										 |  |  |     display_install_times if Homebrew.args.display_times? | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def display_caveats | 
					
						
							|  |  |  |     return if @formula_count <= 1
 | 
					
						
							|  |  |  |     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| | 
					
						
							|  |  |  |       ohai c[:formula], c[:caveats] | 
					
						
							|  |  |  |     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| | 
					
						
							| 
									
										
										
										
											2019-10-03 08:50:45 +02:00
										 |  |  |       puts format("%<formula>-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 |