brew/Library/Homebrew/cmd/analytics.rb

56 lines
1.3 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2019-04-17 18:25:08 +09:00
require "cli/parser"
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) }
def analytics_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
2019-08-06 14:17:17 -04:00
`analytics` [<subcommand>]
Control Homebrew's anonymous aggregate user behaviour analytics.
Read more at <https://docs.brew.sh/Analytics>.
`brew analytics` [`state`]:
Display the current state of Homebrew's analytics.
2020-11-12 10:40:41 -05:00
`brew analytics` (`on`|`off`):
Turn Homebrew's analytics on or off respectively.
`brew analytics regenerate-uuid`:
Regenerate the UUID used for Homebrew's analytics.
EOS
2020-11-12 10:40:41 -05:00
max_named 1
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
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
raise UsageError, "unknown subcommand: #{args.named.first}"
2016-05-01 22:04:46 +08:00
end
end
end