Merge pull request #5566 from GauthamGoli/analytics-args

analytics: Use CLI::Parser to parse args
This commit is contained in:
Gautham Goli 2019-01-22 18:57:35 +05:30 committed by GitHub
commit 8c8eec1b1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,15 +8,35 @@
#: * `analytics` `regenerate-uuid`:
#: Regenerate UUID used in Homebrew's analytics.
require "cli_parser"
module Homebrew
module_function
def analytics_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`analytics` (`on`|`off`) [`state`] [`regenerate-uuid`]
If `on`|`off` is passed, turn Homebrew's analytics on or off respectively.
If `state` is passed, display anonymous user behaviour analytics state.
Read more at <https://docs.brew.sh/Analytics>.
If `regenerate-uuid` is passed, regenerate UUID used in Homebrew's analytics.
EOS
switch :verbose
switch :debug
end
end
def analytics
analytics_args.parse
config_file = HOMEBREW_REPOSITORY/".git/config"
raise UsageError if ARGV.named.size > 1
raise UsageError if args.remaining.size > 1
case ARGV.named.first
case args.remaining.first
when nil, "state"
analyticsdisabled =
Utils.popen_read("git config --file=#{config_file} --get homebrew.analyticsdisabled").chomp