Pass args to Analytics instead of using global args.

This commit is contained in:
Markus Reiter 2020-07-24 23:16:30 +02:00
parent 25b3632c4c
commit 6c050492ee
3 changed files with 20 additions and 20 deletions

View File

@ -46,7 +46,7 @@ module Cask
def self.info(cask)
puts get_info(cask)
::Utils::Analytics.cask_output(cask)
::Utils::Analytics.cask_output(cask, args: Homebrew::CLI::Args.new)
end
def self.title_info(cask)

View File

@ -96,7 +96,7 @@ module Homebrew
def print_info
if args.no_named?
if args.analytics?
Utils::Analytics.output
Utils::Analytics.output(args: args)
elsif HOMEBREW_CELLAR.exist?
count = Formula.racks.length
puts "#{count} #{"keg".pluralize(count)}, #{HOMEBREW_CELLAR.dup.abv}"
@ -107,13 +107,13 @@ module Homebrew
begin
formula = Formulary.factory(f)
if args.analytics?
Utils::Analytics.formula_output(formula)
Utils::Analytics.formula_output(formula, args: args)
else
info_formula(formula)
info_formula(formula, args: args)
end
rescue FormulaUnavailableError => e
if args.analytics?
Utils::Analytics.output(filter: f)
Utils::Analytics.output(filter: f, args: args)
next
end
ofail e.message
@ -159,7 +159,7 @@ module Homebrew
end
end
def info_formula(f)
def info_formula(f, args:)
specs = []
if stable = f.stable
@ -239,7 +239,7 @@ module Homebrew
caveats = Caveats.new(f)
ohai "Caveats", caveats.to_s unless caveats.empty?
Utils::Analytics.formula_output(f)
Utils::Analytics.formula_output(f, args: args)
end
def decorate_dependencies(dependencies)

View File

@ -116,9 +116,9 @@ module Utils
config_delete(:analyticsuuid)
end
def output(filter: nil)
days = Homebrew.args.days || "30"
category = Homebrew.args.category || "install"
def output(filter: nil, args:)
days = args.days || "30"
category = args.category || "install"
json = formulae_brew_sh_json("analytics/#{category}/#{days}d.json")
return if json.blank? || json["items"].blank?
@ -147,8 +147,8 @@ module Utils
table_output(category, days, results, os_version: os_version, cask_install: cask_install)
end
def get_analytics(json)
full_analytics = Homebrew.args.analytics? || Homebrew.args.verbose?
def get_analytics(json, args:)
full_analytics = args.analytics? || Homebrew.args.verbose?
ohai "Analytics"
json["analytics"].each do |category, value|
@ -158,11 +158,11 @@ module Utils
value.each do |days, results|
days = days.to_i
if full_analytics
if Homebrew.args.days.present?
next if Homebrew.args.days&.to_i != days
if args.days.present?
next if args.days&.to_i != days
end
if Homebrew.args.category.present?
next if Homebrew.args.category != category
if args.category.present?
next if args.category != category
end
table_output(category, days, results)
@ -176,18 +176,18 @@ module Utils
end
end
def formula_output(f)
def formula_output(f, args:)
json = formulae_brew_sh_json("#{formula_path}/#{f}.json")
return if json.blank? || json["analytics"].blank?
get_analytics(json)
get_analytics(json, args: args)
end
def cask_output(cask)
def cask_output(cask, args:)
json = formulae_brew_sh_json("#{cask_path}/#{cask}.json")
return if json.blank? || json["analytics"].blank?
get_analytics(json)
get_analytics(json, args: args)
end
def custom_prefix_label