Merge pull request #6763 from EricFromCanada/info-analytics
info: adjust handling of analytics flags
This commit is contained in:
commit
eb019ee330
@ -12,6 +12,10 @@ require "json"
|
|||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
VALID_DAYS = %w[30 90 365].freeze
|
||||||
|
VALID_FORMULA_CATEGORIES = %w[install install-on-request build-error].freeze
|
||||||
|
VALID_CATEGORIES = (VALID_FORMULA_CATEGORIES + %w[cask-install os-version]).freeze
|
||||||
|
|
||||||
def info_args
|
def info_args
|
||||||
Homebrew::CLI::Parser.new do
|
Homebrew::CLI::Parser.new do
|
||||||
usage_banner <<~EOS
|
usage_banner <<~EOS
|
||||||
@ -27,13 +31,14 @@ module Homebrew
|
|||||||
"nor `HOMEBREW_NO_GITHUB_API` are set)."
|
"nor `HOMEBREW_NO_GITHUB_API` are set)."
|
||||||
flag "--days",
|
flag "--days",
|
||||||
depends_on: "--analytics",
|
depends_on: "--analytics",
|
||||||
description: "How many days of global analytics data to retrieve. "\
|
description: "How many days of analytics data to retrieve. "\
|
||||||
"The value for <days> must be `30`, `90` or `365`. The default is `30`."
|
"The value for <days> must be `30`, `90` or `365`. The default is `30`."
|
||||||
flag "--category",
|
flag "--category",
|
||||||
depends_on: "--analytics",
|
depends_on: "--analytics",
|
||||||
description: "Which type of global analytics data to retrieve. "\
|
description: "Which type of analytics data to retrieve. "\
|
||||||
"The value for <category> must be `install`, `install-on-request`, "\
|
"The value for <category> must be `install`, `install-on-request` or `build-error`; "\
|
||||||
"`cask-install`, `build-error` or `os-version`. The default is `install`."
|
"`cask-install` or `os-version` may be specified if <formula> is not. "\
|
||||||
|
"The default is `install`."
|
||||||
switch "--github",
|
switch "--github",
|
||||||
description: "Open the GitHub source page for <formula> in a browser. "\
|
description: "Open the GitHub source page for <formula> in a browser. "\
|
||||||
"To view formula history locally: `brew log -p` <formula>"
|
"To view formula history locally: `brew log -p` <formula>"
|
||||||
@ -56,6 +61,20 @@ module Homebrew
|
|||||||
|
|
||||||
def info
|
def info
|
||||||
info_args.parse
|
info_args.parse
|
||||||
|
if args.days.present?
|
||||||
|
raise UsageError, "days must be one of #{VALID_DAYS.join(", ")}" unless VALID_DAYS.include?(args.days)
|
||||||
|
end
|
||||||
|
|
||||||
|
if args.category.present?
|
||||||
|
if ARGV.named.present? && !VALID_FORMULA_CATEGORIES.include?(args.category)
|
||||||
|
raise UsageError, "category must be one of #{VALID_FORMULA_CATEGORIES.join(", ")} when querying formulae"
|
||||||
|
end
|
||||||
|
|
||||||
|
unless VALID_CATEGORIES.include?(args.category)
|
||||||
|
raise UsageError, "category must be one of #{VALID_CATEGORIES.join(", ")}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if args.json
|
if args.json
|
||||||
raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
|
raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
|
||||||
|
|
||||||
@ -231,18 +250,6 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def analytics_table(category, days, results, os_version: false, cask_install: false)
|
def analytics_table(category, days, results, os_version: false, cask_install: false)
|
||||||
valid_days = %w[30 90 365]
|
|
||||||
if days.present?
|
|
||||||
raise UsageError, "day must be one of #{valid_days.join(", ")}" unless valid_days.include?(days.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
valid_categories = %w[install install-on-request cask-install build-error os-version]
|
|
||||||
if category.present?
|
|
||||||
unless valid_categories.include?(category.tr("_", "-"))
|
|
||||||
raise UsageError, "category must be one of #{valid_categories.join(", ")}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
oh1 "#{category} (#{days} days)"
|
oh1 "#{category} (#{days} days)"
|
||||||
total_count = results.values.inject("+")
|
total_count = results.values.inject("+")
|
||||||
formatted_total_count = format_count(total_count)
|
formatted_total_count = format_count(total_count)
|
||||||
@ -331,15 +338,7 @@ module Homebrew
|
|||||||
|
|
||||||
def output_analytics(filter: nil)
|
def output_analytics(filter: nil)
|
||||||
days = args.days || "30"
|
days = args.days || "30"
|
||||||
valid_days = %w[30 90 365]
|
|
||||||
raise UsageError, "days must be one of #{valid_days.join(", ")}" unless valid_days.include?(days)
|
|
||||||
|
|
||||||
category = args.category || "install"
|
category = args.category || "install"
|
||||||
valid_categories = %w[install install-on-request cask-install build-error os-version]
|
|
||||||
unless valid_categories.include?(category)
|
|
||||||
raise UsageError, "category must be one of #{valid_categories.join(", ")}"
|
|
||||||
end
|
|
||||||
|
|
||||||
json = formulae_api_json("analytics/#{category}/#{days}d.json")
|
json = formulae_api_json("analytics/#{category}/#{days}d.json")
|
||||||
return if json.blank? || json["items"].blank?
|
return if json.blank? || json["items"].blank?
|
||||||
|
|
||||||
@ -376,6 +375,7 @@ module Homebrew
|
|||||||
|
|
||||||
ohai "Analytics"
|
ohai "Analytics"
|
||||||
json["analytics"].each do |category, value|
|
json["analytics"].each do |category, value|
|
||||||
|
category = category.tr("_", "-")
|
||||||
analytics = []
|
analytics = []
|
||||||
|
|
||||||
value.each do |days, results|
|
value.each do |days, results|
|
||||||
@ -384,9 +384,8 @@ module Homebrew
|
|||||||
if args.days.present?
|
if args.days.present?
|
||||||
next if args.days&.to_i != days
|
next if args.days&.to_i != days
|
||||||
end
|
end
|
||||||
|
|
||||||
if args.category.present?
|
if args.category.present?
|
||||||
next if args.category.tr("-", "_") != category
|
next if args.category != category
|
||||||
end
|
end
|
||||||
|
|
||||||
analytics_table(category, days, results)
|
analytics_table(category, days, results)
|
||||||
|
|||||||
@ -211,9 +211,9 @@ If *`formula`* is provided, show summary of information about *`formula`*.
|
|||||||
* `--analytics`:
|
* `--analytics`:
|
||||||
List global Homebrew analytics data or, if specified, installation and build error data for *`formula`* (provided neither `HOMEBREW_NO_ANALYTICS` nor `HOMEBREW_NO_GITHUB_API` are set).
|
List global Homebrew analytics data or, if specified, installation and build error data for *`formula`* (provided neither `HOMEBREW_NO_ANALYTICS` nor `HOMEBREW_NO_GITHUB_API` are set).
|
||||||
* `--days`:
|
* `--days`:
|
||||||
How many days of global analytics data to retrieve. The value for *`days`* must be `30`, `90` or `365`. The default is `30`.
|
How many days of analytics data to retrieve. The value for *`days`* must be `30`, `90` or `365`. The default is `30`.
|
||||||
* `--category`:
|
* `--category`:
|
||||||
Which type of global analytics data to retrieve. The value for *`category`* must be `install`, `install-on-request`, `cask-install`, `build-error` or `os-version`. The default is `install`.
|
Which type of analytics data to retrieve. The value for *`category`* must be `install`, `install-on-request` or `build-error`; `cask-install` or `os-version` may be specified if *`formula`* is not. The default is `install`.
|
||||||
* `--github`:
|
* `--github`:
|
||||||
Open the GitHub source page for *`formula`* in a browser. To view formula history locally: `brew log -p` *`formula`*
|
Open the GitHub source page for *`formula`* in a browser. To view formula history locally: `brew log -p` *`formula`*
|
||||||
* `--json`:
|
* `--json`:
|
||||||
|
|||||||
@ -251,11 +251,11 @@ List global Homebrew analytics data or, if specified, installation and build err
|
|||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-days\fR
|
\fB\-\-days\fR
|
||||||
How many days of global analytics data to retrieve\. The value for \fIdays\fR must be \fB30\fR, \fB90\fR or \fB365\fR\. The default is \fB30\fR\.
|
How many days of analytics data to retrieve\. The value for \fIdays\fR must be \fB30\fR, \fB90\fR or \fB365\fR\. The default is \fB30\fR\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-category\fR
|
\fB\-\-category\fR
|
||||||
Which type of global analytics data to retrieve\. The value for \fIcategory\fR must be \fBinstall\fR, \fBinstall\-on\-request\fR, \fBcask\-install\fR, \fBbuild\-error\fR or \fBos\-version\fR\. The default is \fBinstall\fR\.
|
Which type of analytics data to retrieve\. The value for \fIcategory\fR must be \fBinstall\fR, \fBinstall\-on\-request\fR or \fBbuild\-error\fR; \fBcask\-install\fR or \fBos\-version\fR may be specified if \fIformula\fR is not\. The default is \fBinstall\fR\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-github\fR
|
\fB\-\-github\fR
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user