Port Homebrew::Cmd::Analytics
This commit is contained in:
parent
02a0ea8449
commit
3cedf33150
@ -1,14 +1,13 @@
|
|||||||
# 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
|
||||||
sig { returns(CLI::Parser) }
|
cmd_args do
|
||||||
def analytics_args
|
|
||||||
Homebrew::CLI::Parser.new do
|
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Control Homebrew's anonymous aggregate user behaviour analytics.
|
Control Homebrew's anonymous aggregate user behaviour analytics.
|
||||||
Read more at <https://docs.brew.sh/Analytics>.
|
Read more at <https://docs.brew.sh/Analytics>.
|
||||||
@ -22,12 +21,9 @@ module Homebrew
|
|||||||
|
|
||||||
named_args %w[state on off regenerate-uuid], max: 1
|
named_args %w[state on off regenerate-uuid], max: 1
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
sig { void }
|
|
||||||
def analytics
|
|
||||||
args = analytics_args.parse
|
|
||||||
|
|
||||||
|
sig { override.void }
|
||||||
|
def run
|
||||||
case args.named.first
|
case args.named.first
|
||||||
when nil, "state"
|
when nil, "state"
|
||||||
if Utils::Analytics.disabled?
|
if Utils::Analytics.disabled?
|
||||||
@ -48,4 +44,6 @@ module Homebrew
|
|||||||
raise UsageError, "unknown subcommand: #{args.named.first}"
|
raise UsageError, "unknown subcommand: #{args.named.first}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user