| 
									
										
										
										
											2020-11-25 17:03:23 +01:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2019-01-20 20:04:19 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08: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) } | 
					
						
							| 
									
										
										
										
											2019-01-20 20:04:19 +05:30
										 |  |  |   def analytics_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2020-04-18 12:09:30 -04:00
										 |  |  |         Control Homebrew's anonymous aggregate user behaviour analytics. | 
					
						
							| 
									
										
										
										
											2019-01-20 20:04:19 +05:30
										 |  |  |         Read more at <https://docs.brew.sh/Analytics>. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 12:09:30 -04:00
										 |  |  |         `brew analytics` [`state`]: | 
					
						
							|  |  |  |         Display the current state of Homebrew's analytics. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  |         `brew analytics` (`on`|`off`): | 
					
						
							| 
									
										
										
										
											2020-04-18 12:09:30 -04:00
										 |  |  |         Turn Homebrew's analytics on or off respectively. | 
					
						
							| 
									
										
										
										
											2019-01-20 20:04:19 +05:30
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  |       named_args %w[state on off regenerate-uuid], max: 1
 | 
					
						
							| 
									
										
										
										
											2019-01-20 20:04:19 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |   def analytics | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     args = analytics_args.parse | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:15 +00:00
										 |  |  |     case args.named.first | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |     when nil, "state" | 
					
						
							| 
									
										
										
										
											2019-11-22 09:08:31 +00:00
										 |  |  |       if Utils::Analytics.disabled? | 
					
						
							|  |  |  |         puts "Analytics are disabled." | 
					
						
							| 
									
										
										
										
											2023-02-20 09:05:15 +00:00
										 |  |  |       elsif Homebrew::EnvConfig.no_google_analytics? | 
					
						
							|  |  |  |         puts "InfluxDB analytics are enabled." | 
					
						
							|  |  |  |         puts "Google Analytics are disabled." | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2019-11-22 09:08:31 +00:00
										 |  |  |         puts "Analytics are enabled." | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |       end | 
					
						
							|  |  |  |     when "on" | 
					
						
							| 
									
										
										
										
											2019-11-22 09:08:31 +00:00
										 |  |  |       Utils::Analytics.enable! | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |     when "off" | 
					
						
							| 
									
										
										
										
											2019-11-22 09:08:31 +00:00
										 |  |  |       Utils::Analytics.disable! | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |     when "regenerate-uuid" | 
					
						
							| 
									
										
										
										
											2023-02-20 09:05:15 +00:00
										 |  |  |       Utils::Analytics.delete_uuid! | 
					
						
							|  |  |  |       opoo "Homebrew no longer uses an analytics UUID so this has been deleted!" | 
					
						
							|  |  |  |       puts "brew analytics regenerate-uuid is no longer necessary." | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2020-04-18 12:09:30 -04:00
										 |  |  |       raise UsageError, "unknown subcommand: #{args.named.first}" | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |