Port Homebrew::Cmd::Analytics

This commit is contained in:
Douglas Eichelberger 2024-03-29 16:13:34 -07:00
parent 02a0ea8449
commit 3cedf33150
2 changed files with 38 additions and 39 deletions

View File

@ -1,51 +1,49 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "abstract_command"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
module_function module Cmd
class Analytics < AbstractCommand
cmd_args do
description <<~EOS
Control Homebrew's anonymous aggregate user behaviour analytics.
Read more at <https://docs.brew.sh/Analytics>.
sig { returns(CLI::Parser) } `brew analytics` [`state`]:
def analytics_args Display the current state of Homebrew's analytics.
Homebrew::CLI::Parser.new do
description <<~EOS
Control Homebrew's anonymous aggregate user behaviour analytics.
Read more at <https://docs.brew.sh/Analytics>.
`brew analytics` [`state`]: `brew analytics` (`on`|`off`):
Display the current state of Homebrew's analytics. Turn Homebrew's analytics on or off respectively.
EOS
`brew analytics` (`on`|`off`): named_args %w[state on off regenerate-uuid], max: 1
Turn Homebrew's analytics on or off respectively. end
EOS
sig { override.void }
named_args %w[state on off regenerate-uuid], max: 1 def run
end case args.named.first
end when nil, "state"
if Utils::Analytics.disabled?
sig { void } puts "InfluxDB analytics are disabled."
def analytics else
args = analytics_args.parse puts "InfluxDB analytics are enabled."
end
case args.named.first puts "Google Analytics were destroyed."
when nil, "state" when "on"
if Utils::Analytics.disabled? Utils::Analytics.enable!
puts "InfluxDB analytics are disabled." when "off"
else Utils::Analytics.disable!
puts "InfluxDB analytics are enabled." when "regenerate-uuid"
Utils::Analytics.delete_uuid!
opoo "Homebrew no longer uses an analytics UUID so this has been deleted!"
puts "brew analytics regenerate-uuid is no longer necessary."
else
raise UsageError, "unknown subcommand: #{args.named.first}"
end
end end
puts "Google Analytics were destroyed."
when "on"
Utils::Analytics.enable!
when "off"
Utils::Analytics.disable!
when "regenerate-uuid"
Utils::Analytics.delete_uuid!
opoo "Homebrew no longer uses an analytics UUID so this has been deleted!"
puts "brew analytics regenerate-uuid is no longer necessary."
else
raise UsageError, "unknown subcommand: #{args.named.first}"
end end
end end
end end

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cmd/analytics"
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
RSpec.describe "brew analytics" do RSpec.describe Homebrew::Cmd::Analytics do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
it "when HOMEBREW_NO_ANALYTICS is unset is disabled after running `brew analytics off`", :integration_test do it "when HOMEBREW_NO_ANALYTICS is unset is disabled after running `brew analytics off`", :integration_test do