2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
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
|
|
|
|
usage_banner <<~EOS
|
2019-08-06 14:17:17 -04:00
|
|
|
`analytics` [<subcommand>]
|
2019-01-20 20:04:19 +05:30
|
|
|
|
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.
|
|
|
|
|
|
|
|
`brew analytics` [`on`|`off`]:
|
|
|
|
Turn Homebrew's analytics on or off respectively.
|
|
|
|
|
|
|
|
`brew analytics regenerate-uuid`:
|
|
|
|
Regenerate the UUID used for Homebrew's analytics.
|
2019-01-20 20:04:19 +05:30
|
|
|
EOS
|
2019-12-13 16:50:54 -05:00
|
|
|
max_named 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."
|
2016-05-01 22:04:46 +08:00
|
|
|
else
|
2019-11-22 09:08:31 +00:00
|
|
|
puts "Analytics are enabled."
|
|
|
|
puts "UUID: #{Utils::Analytics.uuid}" if Utils::Analytics.uuid.present?
|
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"
|
2019-11-22 09:08:31 +00:00
|
|
|
Utils::Analytics.regenerate_uuid!
|
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
|