Skip to content

Commit

Permalink
Merge pull request #18172 from cho-m/brew-info-size
Browse files Browse the repository at this point in the history
cmd/info: show size information
  • Loading branch information
MikeMcQuaid authored Sep 25, 2024
2 parents 90597f7 + ea0776c commit e030625
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 12 deletions.
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 @@ 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-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 @@ class Info < AbstractCommand
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 @@ def info_formula(formula)
]
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
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
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
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"]
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
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
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 @@ def tab_attributes
{}
end

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

resource.bottle_size
end

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

resource.installed_size
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

0 comments on commit e030625

Please sign in to comment.