| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  | #:  * `analytics` [`state`]: | 
					
						
							|  |  |  | #:    Display anonymous user behaviour analytics state. | 
					
						
							| 
									
										
										
										
											2018-02-22 19:46:58 +00:00
										 |  |  | #:    Read more at <https://docs.brew.sh/Analytics>. | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  | #: | 
					
						
							|  |  |  | #:  * `analytics` (`on`|`off`): | 
					
						
							|  |  |  | #:    Turn on/off Homebrew's analytics. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:  * `analytics` `regenerate-uuid`: | 
					
						
							|  |  |  | #:    Regenerate UUID used in Homebrew's analytics. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |   def analytics | 
					
						
							|  |  |  |     config_file = HOMEBREW_REPOSITORY/".git/config" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     raise UsageError if ARGV.named.size > 1
 | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |     case ARGV.named.first | 
					
						
							|  |  |  |     when nil, "state" | 
					
						
							| 
									
										
										
										
											2018-09-17 22:02:00 +02:00
										 |  |  |       analyticsdisabled = | 
					
						
							|  |  |  |         Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsdisabled").chomp | 
					
						
							|  |  |  |       uuid = | 
					
						
							|  |  |  |         Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsuuid").chomp | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |       if ENV["HOMEBREW_NO_ANALYTICS"] | 
					
						
							|  |  |  |         puts "Analytics is disabled (by HOMEBREW_NO_ANALYTICS)." | 
					
						
							|  |  |  |       elsif analyticsdisabled == "true" | 
					
						
							|  |  |  |         puts "Analytics is disabled." | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         puts "Analytics is enabled." | 
					
						
							| 
									
										
										
										
											2018-09-17 22:02:00 +02:00
										 |  |  |         puts "UUID: #{uuid}" if uuid.present? | 
					
						
							| 
									
										
										
										
											2016-05-01 22:04:46 +08:00
										 |  |  |       end | 
					
						
							|  |  |  |     when "on" | 
					
						
							|  |  |  |       safe_system "git", "config", "--file=#{config_file}", | 
					
						
							|  |  |  |                                    "--replace-all", "homebrew.analyticsdisabled", "false" | 
					
						
							|  |  |  |       safe_system "git", "config", "--file=#{config_file}", | 
					
						
							|  |  |  |                                    "--replace-all", "homebrew.analyticsmessage", "true" | 
					
						
							|  |  |  |     when "off" | 
					
						
							|  |  |  |       safe_system "git", "config", "--file=#{config_file}", | 
					
						
							|  |  |  |                                    "--replace-all", "homebrew.analyticsdisabled", "true" | 
					
						
							|  |  |  |       system "git", "config", "--file=#{config_file}", "--unset-all", "homebrew.analyticsuuid" | 
					
						
							|  |  |  |     when "regenerate-uuid" | 
					
						
							|  |  |  |       # it will be regenerated in next run. | 
					
						
							|  |  |  |       system "git", "config", "--file=#{config_file}", "--unset-all", "homebrew.analyticsuuid" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       raise UsageError | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |