diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index f1e23e31f3..f3da79755f 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -1,8 +1,11 @@ #: * `info`: #: Display brief statistics for your Homebrew installation. #: -#: * `info` : -#: Display information about . +#: * `info` (`--verbose`): +#: Display information about 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` : #: Open a browser to the GitHub History page for . @@ -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) diff --git a/docs/Manpage.md b/docs/Manpage.md index 81a833be4d..e329e0f321 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -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`. diff --git a/docs/Querying-Brew.md b/docs/Querying-Brew.md index dd884d7d9b..4b03db80b6 100644 --- a/docs/Querying-Brew.md +++ b/docs/Querying-Brew.md @@ -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. diff --git a/manpages/brew.1 b/manpages/brew.1 index d53f310837..1459d9377b 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -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\.