Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/info: show size information #18172

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
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-manifest",
description: "Fetch GitHub Packages manifest for extra information when <formula> is not installed."
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,8 @@
conflicts "--installed", "--eval-all"
conflicts "--installed", "--all"
conflicts "--formula", "--cask"
conflicts "--fetch-manifest", "--cask"
conflicts "--fetch-manifest", "--json"

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L313 - L314 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 318 in Library/Homebrew/cmd/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/info.rb#L318

Added line #L318 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 @@
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 @@
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
cho-m marked this conversation as resolved.
Show resolved Hide resolved
return @manifest_annotations unless @manifest_annotations.nil?

json = begin
JSON.parse(cached_download.read)
rescue JSON::ParserError
Expand All @@ -336,14 +362,7 @@
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
16 changes: 16 additions & 0 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,22 @@
{}
end

sig { returns(T.nilable(Integer)) }
def bottle_size
resource = github_packages_manifest_resource

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/software_spec.rb#L441

Added line #L441 was not covered by tests
return unless resource&.downloaded?

resource.bottle_size

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/software_spec.rb#L444

Added line #L444 was not covered by tests
end

sig { returns(T.nilable(Integer)) }
def installed_size
resource = github_packages_manifest_resource

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/software_spec.rb#L449

Added line #L449 was not covered by tests
return unless resource&.downloaded?

resource.installed_size

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/software_spec.rb#L452

Added line #L452 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-manifest
--formula
--github
--help
Expand Down Expand Up @@ -1229,6 +1230,7 @@ _brew_info() {
--days
--debug
--eval-all
--fetch-manifest
--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-manifest -d 'Fetch GitHub Packages manifest for extra information when formula is not installed'
__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-manifest -d 'Fetch GitHub Packages manifest for extra information when formula is not installed'
__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
10 changes: 6 additions & 4 deletions completions/zsh/_brew
Original file line number Diff line number Diff line change
Expand Up @@ -414,18 +414,19 @@ _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]' \
'(--cask --json)--fetch-manifest[Fetch GitHub Packages manifest for extra information when formula is not installed]' \
'--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-manifest)--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]' \
- formula \
'(--cask)--formula[Treat all named arguments as formulae]' \
'*::formula:__brew_formulae' \
- cask \
'(--formula)--cask[Treat all named arguments as casks]' \
'(--formula --fetch-manifest)--cask[Treat all named arguments as casks]' \
'*::cask:__brew_casks'
}

Expand Down Expand Up @@ -1065,18 +1066,19 @@ _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]' \
'(--cask --json)--fetch-manifest[Fetch GitHub Packages manifest for extra information when formula is not installed]' \
'--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-manifest)--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]' \
- formula \
'(--cask)--formula[Treat all named arguments as formulae]' \
'*::formula:__brew_formulae' \
- cask \
'(--formula)--cask[Treat all named arguments as casks]' \
'(--formula --fetch-manifest)--cask[Treat all named arguments as casks]' \
'*::cask:__brew_casks'
}

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-manifest`

: Fetch GitHub Packages manifest for extra information when *`formula`* is not
installed.

`--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\-manifest\fP
Fetch GitHub Packages manifest for extra information when \fIformula\fP is not installed\.
.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
Loading