aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
diff options
context:
space:
mode:
authorXu Cheng2016-05-01 22:04:46 +0800
committerXu Cheng2016-05-01 22:04:46 +0800
commit98aff27317eaf50c869341e04562062ecd09bd85 (patch)
tree94cbc46aa759141d4684d9c850468e1db507794f /Library/Homebrew/cmd
parent90d3317d7dc9d809d7fc8da15e824161a0ce3008 (diff)
downloadbrew-98aff27317eaf50c869341e04562062ecd09bd85.tar.bz2
add `brew analytics` command (#173)
Diffstat (limited to 'Library/Homebrew/cmd')
-rw-r--r--Library/Homebrew/cmd/analytics.rb46
-rw-r--r--Library/Homebrew/cmd/update-report.rb2
2 files changed, 47 insertions, 1 deletions
diff --git a/Library/Homebrew/cmd/analytics.rb b/Library/Homebrew/cmd/analytics.rb
new file mode 100644
index 000000000..649c53710
--- /dev/null
+++ b/Library/Homebrew/cmd/analytics.rb
@@ -0,0 +1,46 @@
+#: * `analytics` [`state`]:
+#: Display anonymous user behaviour analytics state.
+#: Read more at <https://git.io/brew-analytics>.
+#:
+#: * `analytics` (`on`|`off`):
+#: Turn on/off Homebrew's analytics.
+#:
+#: * `analytics` `regenerate-uuid`:
+#: Regenerate UUID used in Homebrew's analytics.
+
+module Homebrew
+ def analytics
+ config_file = HOMEBREW_REPOSITORY/".git/config"
+
+ raise UsageError if ARGV.named.size > 1
+ case ARGV.named.first
+ when nil, "state"
+ analyticsdisabled = \
+ Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsdisabled").chuzzle
+ uuid = \
+ Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsuuid").chuzzle
+ 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."
+ puts "UUID: #{uuid}" if uuid
+ 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
diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb
index 53b9d639a..1d9822ae5 100644
--- a/Library/Homebrew/cmd/update-report.rb
+++ b/Library/Homebrew/cmd/update-report.rb
@@ -17,7 +17,7 @@ module Homebrew
Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsmessage").chuzzle
analytics_disabled = \
Utils.popen_read("git", "config", "--local", "--get", "homebrew.analyticsdisabled").chuzzle
- if analytics_message_displayed != "true" && analytics_disabled != "true"
+ if analytics_message_displayed != "true" && analytics_disabled != "true" && !ENV["HOMEBREW_NO_ANALYTICS"]
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
ohai "Homebrew has enabled anonymous aggregate user behaviour analytics"
puts "Read the analytics documentation (and how to opt-out) here:"