brew/Library/Homebrew/cmd/analytics.rb

48 lines
1.1 KiB
Ruby
Raw Normal View History

# 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
2016-09-26 01:44:51 +02:00
module_function
def analytics_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
2019-08-06 14:17:17 -04:00
`analytics` [<subcommand>]
If `on` or `off` is passed, turn Homebrew's analytics on or off respectively.
If `state` is passed, display the current anonymous user behaviour analytics state.
Read more at <https://docs.brew.sh/Analytics>.
2019-08-06 14:22:24 -04:00
If `regenerate-uuid` is passed, regenerate the UUID used in Homebrew's analytics.
EOS
switch :verbose
switch :debug
max_named 1
end
end
2016-05-01 22:04:46 +08:00
def analytics
analytics_args.parse
2016-05-01 22:04:46 +08:00
case args.remaining.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."
2016-05-01 22:04:46 +08:00
end
end
end