Skip to content

Commit

Permalink
cmd/info: show size information
Browse files Browse the repository at this point in the history
Co-authored-by: Mike McQuaid <[email protected]>
Co-authored-by: Markus Reiter <[email protected]>
  • Loading branch information
3 people committed Sep 24, 2024
1 parent bd3c7f8 commit e30935d
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 10 deletions.
14 changes: 14 additions & 0 deletions Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Info < AbstractCommand
switch "--github",
description: "Open the GitHub source page for <formula> and <cask> in a browser. " \
"To view the history locally: `brew log -p` <formula> or <cask>"
switch "--fetch-manifests",
description: "Fetch GitHub Packages manifests for extra information on not installed formulae."
flag "--json",
description: "Print a JSON representation. Currently the default value for <version> is `v1` for " \
"<formula>. For <formula> and <cask> use `v2`. See the docs for examples of using the " \
Expand All @@ -69,6 +71,7 @@ class Info < AbstractCommand
conflicts "--installed", "--eval-all"
conflicts "--installed", "--all"
conflicts "--formula", "--cask"
conflicts "--fetch-manifests", "--json"

named_args [:formula, :cask]
end
Expand Down Expand Up @@ -303,6 +306,17 @@ def info_formula(formula)
]
if kegs.empty?
puts "Not installed"
unless (bottle = formula.bottle).nil?
begin
bottle.fetch_tab(quiet: !args.debug?) if args.fetch_manifests?
bottle_size = bottle.bottle_size
installed_size = bottle.installed_size

Check warning on line 313 in Library/Homebrew/cmd/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/info.rb#L312-L313

Added lines #L312 - L313 were not covered by tests
puts "Bottle Size: #{disk_usage_readable(bottle_size)}" if bottle_size
puts "Installed Size: #{disk_usage_readable(installed_size)}" if installed_size
rescue RuntimeError => e
odebug e

Check warning on line 317 in Library/Homebrew/cmd/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/info.rb#L317

Added line #L317 was not covered by tests
end
end
else
puts "Installed"
kegs.each do |keg|
Expand Down
35 changes: 27 additions & 8 deletions Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class Error < RuntimeError; end
def initialize(bottle)
super("#{bottle.name}_bottle_manifest")
@bottle = bottle
@manifest_annotations = nil

Check warning on line 309 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L309

Added line #L309 was not covered by tests
end

def verify_download_integrity(_filename)
Expand All @@ -314,6 +315,31 @@ def verify_download_integrity(_filename)
end

def tab
tab = manifest_annotations["sh.brew.tab"]

Check warning on line 318 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L318

Added line #L318 was not covered by tests
raise Error, "Couldn't find tab from manifest." if tab.blank?

begin
JSON.parse(tab)

Check warning on line 322 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L322

Added line #L322 was not covered by tests
rescue JSON::ParserError
raise Error, "Couldn't parse tab JSON."

Check warning on line 324 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L324

Added line #L324 was not covered by tests
end
end

sig { returns(T.nilable(Integer)) }
def bottle_size
manifest_annotations["sh.brew.bottle.size"]&.to_i
end

sig { returns(T.nilable(Integer)) }
def installed_size
manifest_annotations["sh.brew.bottle.installed_size"]&.to_i
end

private

def manifest_annotations
return @manifest_annotations unless @manifest_annotations.nil?

json = begin
JSON.parse(cached_download.read)
rescue JSON::ParserError
Expand All @@ -336,14 +362,7 @@ def tab
end
raise Error, "Couldn't find manifest matching bottle checksum." if manifest_annotations.blank?

tab = manifest_annotations["sh.brew.tab"]
raise Error, "Couldn't find tab from manifest." if tab.blank?

begin
JSON.parse(tab)
rescue JSON::ParserError
raise Error, "Couldn't parse tab JSON."
end
@manifest_annotations = manifest_annotations

Check warning on line 365 in Library/Homebrew/resource.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource.rb#L365

Added line #L365 was not covered by tests
end
end

Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,20 @@ def tab_attributes
{}
end

sig { returns(T.nilable(Integer)) }
def bottle_size
return unless (resource = github_packages_manifest_resource)&.downloaded?

resource.bottle_size

Check warning on line 443 in Library/Homebrew/software_spec.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/software_spec.rb#L443

Added line #L443 was not covered by tests
end

sig { returns(T.nilable(Integer)) }
def installed_size
return unless (resource = github_packages_manifest_resource)&.downloaded?

resource.installed_size

Check warning on line 450 in Library/Homebrew/software_spec.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/software_spec.rb#L450

Added line #L450 was not covered by tests
end

sig { returns(Filename) }
def filename
Filename.create(resource.owner, @tag, @spec.rebuild)
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/info.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions completions/bash/brew
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ _brew_abv() {
--days
--debug
--eval-all
--fetch-manifests
--formula
--github
--help
Expand Down Expand Up @@ -1229,6 +1230,7 @@ _brew_info() {
--days
--debug
--eval-all
--fetch-manifests
--formula
--github
--help
Expand Down
2 changes: 2 additions & 0 deletions completions/fish/brew.fish
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ __fish_brew_complete_arg 'abv' -l category -d 'Which type of analytics data to r
__fish_brew_complete_arg 'abv' -l days -d 'How many days of analytics data to retrieve. The value for days must be `30`, `90` or `365`. The default is `30`'
__fish_brew_complete_arg 'abv' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'abv' -l eval-all -d 'Evaluate all available formulae and casks, whether installed or not, to print their JSON. Implied if `HOMEBREW_EVAL_ALL` is set'
__fish_brew_complete_arg 'abv' -l fetch-manifests -d 'Fetch GitHub Packages manifests for extra information on not installed formulae'
__fish_brew_complete_arg 'abv' -l formula -d 'Treat all named arguments as formulae'
__fish_brew_complete_arg 'abv' -l github -d 'Open the GitHub source page for formula and cask in a browser. To view the history locally: `brew log -p` formula or cask'
__fish_brew_complete_arg 'abv' -l help -d 'Show this message'
Expand Down Expand Up @@ -840,6 +841,7 @@ __fish_brew_complete_arg 'info' -l category -d 'Which type of analytics data to
__fish_brew_complete_arg 'info' -l days -d 'How many days of analytics data to retrieve. The value for days must be `30`, `90` or `365`. The default is `30`'
__fish_brew_complete_arg 'info' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'info' -l eval-all -d 'Evaluate all available formulae and casks, whether installed or not, to print their JSON. Implied if `HOMEBREW_EVAL_ALL` is set'
__fish_brew_complete_arg 'info' -l fetch-manifests -d 'Fetch GitHub Packages manifests for extra information on not installed formulae'
__fish_brew_complete_arg 'info' -l formula -d 'Treat all named arguments as formulae'
__fish_brew_complete_arg 'info' -l github -d 'Open the GitHub source page for formula and cask in a browser. To view the history locally: `brew log -p` formula or cask'
__fish_brew_complete_arg 'info' -l help -d 'Show this message'
Expand Down
6 changes: 4 additions & 2 deletions completions/zsh/_brew
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,11 @@ _brew_abv() {
'--days[How many days of analytics data to retrieve. The value for days must be `30`, `90` or `365`. The default is `30`]' \
'--debug[Display any debugging information]' \
'(--installed)--eval-all[Evaluate all available formulae and casks, whether installed or not, to print their JSON. Implied if `HOMEBREW_EVAL_ALL` is set]' \
'(--json)--fetch-manifests[Fetch GitHub Packages manifests for extra information on not installed formulae]' \
'--github[Open the GitHub source page for formula and cask in a browser. To view the history locally: `brew log -p` formula or cask]' \
'--help[Show this message]' \
'(--eval-all --all)--installed[Print JSON of formulae that are currently installed]' \
'--json[Print a JSON representation. Currently the default value for version is `v1` for formula. For formula and cask use `v2`. See the docs for examples of using the JSON output: https://docs.brew.sh/Querying-Brew]' \
'(--fetch-manifests)--json[Print a JSON representation. Currently the default value for version is `v1` for formula. For formula and cask use `v2`. See the docs for examples of using the JSON output: https://docs.brew.sh/Querying-Brew]' \
'--quiet[Make some output more quiet]' \
'--variations[Include the variations hash in each formula'\''s JSON output]' \
'--verbose[Show more verbose analytics data for formula]' \
Expand Down Expand Up @@ -1065,10 +1066,11 @@ _brew_info() {
'--days[How many days of analytics data to retrieve. The value for days must be `30`, `90` or `365`. The default is `30`]' \
'--debug[Display any debugging information]' \
'(--installed)--eval-all[Evaluate all available formulae and casks, whether installed or not, to print their JSON. Implied if `HOMEBREW_EVAL_ALL` is set]' \
'(--json)--fetch-manifests[Fetch GitHub Packages manifests for extra information on not installed formulae]' \
'--github[Open the GitHub source page for formula and cask in a browser. To view the history locally: `brew log -p` formula or cask]' \
'--help[Show this message]' \
'(--eval-all --all)--installed[Print JSON of formulae that are currently installed]' \
'--json[Print a JSON representation. Currently the default value for version is `v1` for formula. For formula and cask use `v2`. See the docs for examples of using the JSON output: https://docs.brew.sh/Querying-Brew]' \
'(--fetch-manifests)--json[Print a JSON representation. Currently the default value for version is `v1` for formula. For formula and cask use `v2`. See the docs for examples of using the JSON output: https://docs.brew.sh/Querying-Brew]' \
'--quiet[Make some output more quiet]' \
'--variations[Include the variations hash in each formula'\''s JSON output]' \
'--verbose[Show more verbose analytics data for formula]' \
Expand Down
5 changes: 5 additions & 0 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ Display brief statistics for your Homebrew installation. If a *`formula`* or
: Open the GitHub source page for *`formula`* and *`cask`* in a browser. To view
the history locally: `brew log -p` *`formula`* or *`cask`*

`--fetch-manifests`

: Fetch GitHub Packages manifests for extra information on not installed
formulae.

`--json`

: Print a JSON representation. Currently the default value for *`version`* is
Expand Down
3 changes: 3 additions & 0 deletions manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ Which type of analytics data to retrieve\. The value for \fIcategory\fP must be
\fB\-\-github\fP
Open the GitHub source page for \fIformula\fP and \fIcask\fP in a browser\. To view the history locally: \fBbrew log \-p\fP \fIformula\fP or \fIcask\fP
.TP
\fB\-\-fetch\-manifests\fP
Fetch GitHub Packages manifests for extra information on not installed formulae\.
.TP
\fB\-\-json\fP
Print a JSON representation\. Currently the default value for \fIversion\fP is \fBv1\fP for \fIformula\fP\&\. For \fIformula\fP and \fIcask\fP use \fBv2\fP\&\. See the docs for examples of using the JSON output:
.UR https://docs\.brew\.sh/Querying\-Brew
Expand Down

0 comments on commit e30935d

Please sign in to comment.