mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
cmd/info: show size information
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com> Co-authored-by: Markus Reiter <me@reitermark.us>
This commit is contained in:
parent
57ff7b05e9
commit
ea0776c425
@ -45,6 +45,8 @@ module Homebrew
|
||||
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 " \
|
||||
@ -69,6 +71,8 @@ module Homebrew
|
||||
conflicts "--installed", "--eval-all"
|
||||
conflicts "--installed", "--all"
|
||||
conflicts "--formula", "--cask"
|
||||
conflicts "--fetch-manifest", "--cask"
|
||||
conflicts "--fetch-manifest", "--json"
|
||||
|
||||
named_args [:formula, :cask]
|
||||
end
|
||||
@ -303,6 +307,17 @@ module Homebrew
|
||||
]
|
||||
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|
|
||||
|
@ -306,6 +306,7 @@ class Resource
|
||||
def initialize(bottle)
|
||||
super("#{bottle.name}_bottle_manifest")
|
||||
@bottle = bottle
|
||||
@manifest_annotations = nil
|
||||
end
|
||||
|
||||
def verify_download_integrity(_filename)
|
||||
@ -314,6 +315,31 @@ class Resource
|
||||
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
|
||||
@ -336,14 +362,7 @@ class Resource
|
||||
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
|
||||
|
||||
|
@ -436,6 +436,22 @@ class Bottle
|
||||
{}
|
||||
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)
|
||||
|
@ -29,6 +29,9 @@ class Homebrew::Cmd::Info::Args < Homebrew::CLI::Args
|
||||
sig { returns(T::Boolean) }
|
||||
def eval_all?; end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def fetch_manifest?; end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def formula?; end
|
||||
|
||||
|
@ -341,6 +341,7 @@ _brew_abv() {
|
||||
--days
|
||||
--debug
|
||||
--eval-all
|
||||
--fetch-manifest
|
||||
--formula
|
||||
--github
|
||||
--help
|
||||
@ -1229,6 +1230,7 @@ _brew_info() {
|
||||
--days
|
||||
--debug
|
||||
--eval-all
|
||||
--fetch-manifest
|
||||
--formula
|
||||
--github
|
||||
--help
|
||||
|
@ -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'
|
||||
@ -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'
|
||||
|
@ -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]' \
|
||||
'(--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]' \
|
||||
@ -425,7 +426,7 @@ _brew_abv() {
|
||||
'(--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'
|
||||
}
|
||||
|
||||
@ -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]' \
|
||||
'(--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]' \
|
||||
@ -1076,7 +1078,7 @@ _brew_info() {
|
||||
'(--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'
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user