Merge pull request #5877 from EricFromCanada/info-update-options

info: flag and doc fixes and updates
This commit is contained in:
Mike McQuaid 2019-03-14 08:44:13 +00:00 committed by GitHub
commit 9cb518aa61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 36 deletions

View File

@ -13,37 +13,42 @@ module Homebrew
def info_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`info` [<formula>]
`info` [<options>] [<formula>]
Display brief statistics for your Homebrew installation.
If <formula> is specified, show summary of information about <formula>.
EOS
switch "--analytics",
description: "Display Homebrew analytics data (provided neither `HOMEBREW_NO_ANALYTICS` "\
"or `HOMEBREW_NO_GITHUB_API` are set)."
description: "Display 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)."
flag "--days",
depends_on: "--analytics",
description: "The value for `days` must be `30`, `90` or `365`. The default is `30`."
description: "How many days of global analytics data to retrieve. "\
"The value for <days> must be `30`, `90` or `365`. The default is `30`."
flag "--category",
depends_on: "--analytics",
description: "The value for `category` must be `install`, `install-on-request`, "\
"`build-error` or `os-version`. The default is `install`."
description: "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`."
switch "--github",
description: "Open a browser to the GitHub History page for provided <formula>. "\
description: "Open a browser to the GitHub source page for <formula>. "\
"To view formula history locally: `brew log -p` <formula>"
flag "--json",
description: "Print a JSON representation of <formula>. Currently the default and only accepted "\
"value for <version> is `v1`. See the docs for examples of using the JSON "\
"output: <https://docs.brew.sh/Querying-Brew>"
switch "--all",
depends_on: "--json",
description: "Get information on all formulae."
switch "--installed",
depends_on: "--json",
description: "Get information on all installed formulae."
description: "Print JSON of formulae that are currently installed."
switch "--all",
depends_on: "--json",
description: "Print JSON of all available formulae."
switch :verbose,
description: "See more verbose analytics data."
description: "Show more verbose analytics data for <formula>."
switch :debug
conflicts "--all", "--installed"
conflicts "--installed", "--all"
end
end
@ -214,7 +219,7 @@ module Homebrew
def formulae_api_json(endpoint)
return if ENV["HOMEBREW_NO_ANALYTICS"] || ENV["HOMEBREW_NO_GITHUB_API"]
output, = curl_output("--max-time", "3",
output, = curl_output("--max-time", "5",
"https://formulae.brew.sh/api/#{endpoint}")
return if output.blank?
@ -223,7 +228,7 @@ module Homebrew
nil
end
def analytics_table(category, days, results, os_version: false)
def analytics_table(category, days, results, os_version: false, cask_install: false)
oh1 "#{category} (#{days} days)"
total_count = results.values.inject("+")
formatted_total_count = format_count(total_count)
@ -234,6 +239,8 @@ module Homebrew
percent_header = "Percent"
name_with_options_header = if os_version
"macOS Version"
elsif cask_install
"Token"
else
"Name (with options)"
end
@ -311,22 +318,25 @@ module Homebrew
def output_analytics(filter: nil)
days = args.days || "30"
valid_days = %w[30 90 365]
raise ArgumentError("Days must be one of #{valid_days.join(", ")}!") unless valid_days.include?(days)
raise UsageError, "days must be one of #{valid_days.join(", ")}" unless valid_days.include?(days)
category = args.category || "install"
valid_categories = %w[install install-on-request build-error os-version]
valid_categories = %w[install install-on-request cask-install build-error os-version]
unless valid_categories.include?(category)
raise ArgumentError("Categories must be one of #{valid_categories.join(", ")}")
raise UsageError, "category must be one of #{valid_categories.join(", ")}"
end
json = formulae_api_json("analytics/#{category}/#{days}d.json")
return if json.blank? || json["items"].blank?
os_version = category == "os-version"
cask_install = category == "cask-install"
results = {}
json["items"].each do |item|
key = if os_version
item["os_version"]
elsif cask_install
item["cask"]
else
item["formula"]
end
@ -341,7 +351,7 @@ module Homebrew
return
end
analytics_table(category, days, results, os_version: os_version)
analytics_table(category, days, results, os_version: os_version, cask_install: cask_install)
end
def output_formula_analytics(f)

View File

@ -194,24 +194,26 @@ If no logs are found, an error message is presented.
Open *`formula`*'s homepage in a browser. If no formula is provided, open
Homebrew's own homepage in a browser.
### `info` [*`formula`*]
### `info` [*`options`*] [*`formula`*]
Display brief statistics for your Homebrew installation.
If *`formula`* is specified, show summary of information about *`formula`*.
* `--analytics`:
Display Homebrew analytics data (provided neither `HOMEBREW_NO_ANALYTICS` or `HOMEBREW_NO_GITHUB_API` are set).
Display 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`:
The value for `days` must be `30`, `90` or `365`. The default is `30`.
How many days of global analytics data to retrieve. The value for *`days`* must be `30`, `90` or `365`. The default is `30`.
* `--category`:
The value for `category` must be `install`, `install-on-request`, `build-error` or `os-version`. The default is `install`.
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`.
* `--github`:
Open a browser to the GitHub History page for provided *`formula`*. To view formula history locally: `brew log -p` *`formula`*
Open a browser to the GitHub source page for *`formula`*. To view formula history locally: `brew log -p` *`formula`*
* `--json`:
Print a JSON representation of *`formula`*. Currently the default and only accepted value for *`version`* is `v1`. See the docs for examples of using the JSON output: <https://docs.brew.sh/Querying-Brew>
* `--all`:
Get information on all formulae.
* `--installed`:
Get information on all installed formulae.
Print JSON of formulae that are currently installed.
* `--all`:
Print JSON of all available formulae.
### `install` [*`options`*] *`formula`*

View File

@ -230,36 +230,39 @@ The Gist will be marked private and will not appear in listings but will be acce
.SS "\fBhome\fR [\fIformula\fR]"
Open \fIformula\fR\'s homepage in a browser\. If no formula is provided, open Homebrew\'s own homepage in a browser\.
.
.SS "\fBinfo\fR [\fIformula\fR]"
.SS "\fBinfo\fR [\fIoptions\fR] [\fIformula\fR]"
Display brief statistics for your Homebrew installation\.
.
.P
If \fIformula\fR is specified, show summary of information about \fIformula\fR\.
.
.TP
\fB\-\-analytics\fR
Display Homebrew analytics data (provided neither \fBHOMEBREW_NO_ANALYTICS\fR or \fBHOMEBREW_NO_GITHUB_API\fR are set)\.
Display global Homebrew analytics data or, if specified, installation and build error data for \fIformula\fR (provided neither \fBHOMEBREW_NO_ANALYTICS\fR nor \fBHOMEBREW_NO_GITHUB_API\fR are set)\.
.
.TP
\fB\-\-days\fR
The value for \fBdays\fR must be \fB30\fR, \fB90\fR or \fB365\fR\. The default is \fB30\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\.
.
.TP
\fB\-\-category\fR
The value for \fBcategory\fR must be \fBinstall\fR, \fBinstall\-on\-request\fR, \fBbuild\-error\fR or \fBos\-version\fR\. The default is \fBinstall\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\.
.
.TP
\fB\-\-github\fR
Open a browser to the GitHub History page for provided \fIformula\fR\. To view formula history locally: \fBbrew log \-p\fR \fIformula\fR
Open a browser to the GitHub source page for \fIformula\fR\. To view formula history locally: \fBbrew log \-p\fR \fIformula\fR
.
.TP
\fB\-\-json\fR
Print a JSON representation of \fIformula\fR\. Currently the default and only accepted value for \fIversion\fR is \fBv1\fR\. See the docs for examples of using the JSON output: \fIhttps://docs\.brew\.sh/Querying\-Brew\fR
.
.TP
\fB\-\-all\fR
Get information on all formulae\.
\fB\-\-installed\fR
Print JSON of formulae that are currently installed\.
.
.TP
\fB\-\-installed\fR
Get information on all installed formulae\.
\fB\-\-all\fR
Print JSON of all available formulae\.
.
.SS "\fBinstall\fR [\fIoptions\fR] \fIformula\fR"
Install \fIformula\fR\.