Merge pull request #4830 from MikeMcQuaid/info-analytics
cmd/info: display analytics data.
This commit is contained in:
commit
34061628e6
@ -1,8 +1,11 @@
|
||||
#: * `info`:
|
||||
#: Display brief statistics for your Homebrew installation.
|
||||
#:
|
||||
#: * `info` <formula>:
|
||||
#: Display information about <formula>.
|
||||
#: * `info` <formula> (`--verbose`):
|
||||
#: Display information about <formula> and analytics data (provided neither
|
||||
#: `HOMEBREW_NO_ANALYTICS` or `HOMEBREW_NO_GITHUB_API` are set)
|
||||
#:
|
||||
#: Pass `--verbose` to see more detailed analytics data.
|
||||
#:
|
||||
#: * `info` `--github` <formula>:
|
||||
#: Open a browser to the GitHub History page for <formula>.
|
||||
@ -179,6 +182,44 @@ module Homebrew
|
||||
|
||||
caveats = Caveats.new(f)
|
||||
ohai "Caveats", caveats.to_s unless caveats.empty?
|
||||
|
||||
output_analytics(f)
|
||||
end
|
||||
|
||||
def output_analytics(f)
|
||||
return if ENV["HOMEBREW_NO_ANALYTICS"]
|
||||
return if ENV["HOMEBREW_NO_GITHUB_API"]
|
||||
|
||||
formulae_json_url = "https://formulae.brew.sh/api/formula/#{f}.json"
|
||||
output, = curl_output("--max-time", "3", formulae_json_url)
|
||||
return if output.empty?
|
||||
|
||||
json = begin
|
||||
JSON.parse(output)
|
||||
rescue JSON::ParserError
|
||||
nil
|
||||
end
|
||||
return if json.nil? || json.empty? || json["analytics"].empty?
|
||||
|
||||
ohai "Analytics"
|
||||
if ARGV.verbose?
|
||||
json["analytics"].each do |category, value|
|
||||
value.each do |range, results|
|
||||
oh1 "#{category} (#{range})"
|
||||
results.each do |name_with_options, count|
|
||||
puts "#{name_with_options}: #{count}"
|
||||
end
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
json["analytics"].each do |category, value|
|
||||
analytics = value.map do |range, results|
|
||||
"#{results.values.inject("+")} (#{range})"
|
||||
end
|
||||
puts "#{category}: #{analytics.join(", ")}"
|
||||
end
|
||||
end
|
||||
|
||||
def decorate_dependencies(dependencies)
|
||||
|
@ -199,8 +199,11 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note
|
||||
* `info`:
|
||||
Display brief statistics for your Homebrew installation.
|
||||
|
||||
* `info` `formula`:
|
||||
Display information about `formula`.
|
||||
* `info` `formula` (`--verbose`):
|
||||
Display information about `formula` and analytics data (provided neither
|
||||
`HOMEBREW_NO_ANALYTICS` or `HOMEBREW_NO_GITHUB_API` are set)
|
||||
|
||||
Pass `--verbose` to see more detailed analytics data.
|
||||
|
||||
* `info` `--github` `formula`:
|
||||
Open a browser to the GitHub History page for `formula`.
|
||||
|
@ -71,6 +71,10 @@ To find the names of normal (not keg-only) formulae that are installed, but not
|
||||
brew info --json=v1 --installed | jq "map(select(.keg_only == false and .linked_keg == null) | .name)"
|
||||
```
|
||||
|
||||
## formulae.brew.sh
|
||||
|
||||
formulae.brew.sh has a [documented JSON API](https://formulae.brew.sh/docs/api/) which provides access to the `brew info --json=v1` output without needing access to Homebrew.
|
||||
|
||||
## Concluding remarks
|
||||
|
||||
Using the JSON output, queries can be made against Homebrew with less risk of being broken due to Homebrew code changes, and without needing to understand Homebrew's Ruby internals.
|
||||
|
@ -188,7 +188,10 @@ If no logs are found, an error message is presented\.
|
||||
\fBinfo\fR: Display brief statistics for your Homebrew installation\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
\fBinfo\fR \fIformula\fR: Display information about \fIformula\fR\.
|
||||
\fBinfo\fR \fIformula\fR (\fB\-\-verbose\fR): Display information about \fIformula\fR and analytics data (provided neither \fBHOMEBREW_NO_ANALYTICS\fR or \fBHOMEBREW_NO_GITHUB_API\fR are set)
|
||||
.
|
||||
.IP
|
||||
Pass \fB\-\-verbose\fR to see more detailed analytics data\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
\fBinfo\fR \fB\-\-github\fR \fIformula\fR: Open a browser to the GitHub History page for \fIformula\fR\.
|
||||
|
Loading…
x
Reference in New Issue
Block a user