Merge pull request #9220 from reitermarkus/brew-cask-info
Support `--cask` flag in `brew info`.
This commit is contained in:
commit
bcc4a5d62b
@ -49,10 +49,10 @@ module Homebrew
|
||||
.map(&:freeze).freeze
|
||||
end
|
||||
|
||||
def to_formulae_and_casks_and_unavailable(method: nil)
|
||||
def to_formulae_and_casks_and_unavailable(only: nil, method: nil)
|
||||
@to_formulae_casks_unknowns ||= {}
|
||||
@to_formulae_casks_unknowns[method] = downcased_unique_named.map do |name|
|
||||
load_formula_or_cask(name, method: method)
|
||||
load_formula_or_cask(name, only: only, method: method)
|
||||
rescue FormulaOrCaskUnavailableError => e
|
||||
e
|
||||
end.uniq.freeze
|
||||
|
||||
@ -25,11 +25,11 @@ module Homebrew
|
||||
def info_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
usage_banner <<~EOS
|
||||
`info` [<options>] [<formula>]
|
||||
`info` [<options>] [<formula>|<cask>]
|
||||
|
||||
Display brief statistics for your Homebrew installation.
|
||||
|
||||
If <formula> is provided, show summary of information about <formula>.
|
||||
If a <formula> or <cask> is provided, show summary of information about it.
|
||||
EOS
|
||||
switch "--analytics",
|
||||
description: "List global Homebrew analytics data or, if specified, installation and "\
|
||||
@ -61,13 +61,23 @@ module Homebrew
|
||||
switch "-v", "--verbose",
|
||||
description: "Show more verbose analytics data for <formula>."
|
||||
|
||||
switch "--formula", "--formulae",
|
||||
description: "Treat all named arguments as formulae."
|
||||
switch "--cask", "--casks",
|
||||
description: "Treat all named arguments as casks."
|
||||
conflicts "--formula", "--cask"
|
||||
|
||||
conflicts "--installed", "--all"
|
||||
end
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def info
|
||||
args = info_args.parse
|
||||
|
||||
only = :formula if args.formula? && !args.cask?
|
||||
only = :cask if args.cask? && !args.formula?
|
||||
|
||||
if args.analytics?
|
||||
if args.days.present? && !VALID_DAYS.include?(args.days)
|
||||
raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}"
|
||||
@ -83,20 +93,21 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
print_analytics(args: args)
|
||||
print_analytics(args: args, only: only)
|
||||
elsif args.json
|
||||
print_json(args: args)
|
||||
print_json(args: args, only: only)
|
||||
elsif args.github?
|
||||
raise FormulaOrCaskUnspecifiedError if args.no_named?
|
||||
|
||||
exec_browser(*args.named.to_formulae_and_casks.map { |f| github_info(f) })
|
||||
exec_browser(*args.named.to_formulae_and_casks(only: only).map { |f| github_info(f) })
|
||||
elsif args.no_named?
|
||||
print_statistics
|
||||
else
|
||||
print_info(args: args)
|
||||
print_info(args: args, only: only)
|
||||
end
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def print_statistics
|
||||
return unless HOMEBREW_CELLAR.exist?
|
||||
|
||||
@ -104,13 +115,14 @@ module Homebrew
|
||||
puts "#{count} #{"keg".pluralize(count)}, #{HOMEBREW_CELLAR.dup.abv}"
|
||||
end
|
||||
|
||||
def print_analytics(args:)
|
||||
sig { params(args: CLI::Args, only: T.nilable(Symbol)).void }
|
||||
def print_analytics(args:, only: nil)
|
||||
if args.no_named?
|
||||
Utils::Analytics.output(args: args)
|
||||
return
|
||||
end
|
||||
|
||||
args.named.to_formulae_and_casks_and_unavailable.each_with_index do |obj, i|
|
||||
args.named.to_formulae_and_casks_and_unavailable(only: only).each_with_index do |obj, i|
|
||||
puts unless i.zero?
|
||||
|
||||
case obj
|
||||
@ -126,8 +138,9 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def print_info(args:)
|
||||
args.named.to_formulae_and_casks_and_unavailable.each_with_index do |obj, i|
|
||||
sig { params(args: CLI::Args, only: T.nilable(Symbol)).void }
|
||||
def print_info(args:, only: nil)
|
||||
args.named.to_formulae_and_casks_and_unavailable(only: only).each_with_index do |obj, i|
|
||||
puts unless i.zero?
|
||||
|
||||
case obj
|
||||
@ -159,7 +172,8 @@ module Homebrew
|
||||
version_hash[version]
|
||||
end
|
||||
|
||||
def print_json(args:)
|
||||
sig { params(args: CLI::Args, only: T.nilable(Symbol)).void }
|
||||
def print_json(args:, only: nil)
|
||||
raise FormulaOrCaskUnspecifiedError if !(args.all? || args.installed?) && args.no_named?
|
||||
|
||||
json = case json_version(args.json)
|
||||
@ -179,7 +193,7 @@ module Homebrew
|
||||
elsif args.installed?
|
||||
[Formula.installed.sort, Cask::Caskroom.casks.sort_by(&:full_name)]
|
||||
else
|
||||
args.named.to_formulae_to_casks
|
||||
args.named.to_formulae_to_casks(only: only)
|
||||
end
|
||||
|
||||
{
|
||||
|
||||
@ -244,11 +244,11 @@ error message if no logs are found.
|
||||
Open *`formula`*'s homepage in a browser, or open Homebrew's own homepage
|
||||
if no formula is provided.
|
||||
|
||||
### `info` [*`options`*] [*`formula`*]
|
||||
### `info` [*`options`*] [*`formula`*|*`cask`*]
|
||||
|
||||
Display brief statistics for your Homebrew installation.
|
||||
|
||||
If *`formula`* is provided, show summary of information about *`formula`*.
|
||||
If a *`formula`* or *`cask`* is provided, show summary of information about it.
|
||||
|
||||
* `--analytics`:
|
||||
List global Homebrew analytics data or, if specified, installation and build error data for *`formula`* (provided neither `HOMEBREW_NO_ANALYTICS` nor `HOMEBREW_NO_GITHUB_API` are set).
|
||||
@ -266,6 +266,10 @@ If *`formula`* is provided, show summary of information about *`formula`*.
|
||||
Print JSON of all available formulae.
|
||||
* `-v`, `--verbose`:
|
||||
Show more verbose analytics data for *`formula`*.
|
||||
* `--formula`:
|
||||
Treat all named arguments as formulae.
|
||||
* `--cask`:
|
||||
Treat all named arguments as casks.
|
||||
|
||||
### `install` [*`options`*] *`formula`*|*`cask`*
|
||||
|
||||
|
||||
@ -322,11 +322,11 @@ The Gist will be marked private and will not appear in listings but will be acce
|
||||
.SS "\fBhome\fR [\fIformula\fR]"
|
||||
Open \fIformula\fR\'s homepage in a browser, or open Homebrew\'s own homepage if no formula is provided\.
|
||||
.
|
||||
.SS "\fBinfo\fR [\fIoptions\fR] [\fIformula\fR]"
|
||||
.SS "\fBinfo\fR [\fIoptions\fR] [\fIformula\fR|\fIcask\fR]"
|
||||
Display brief statistics for your Homebrew installation\.
|
||||
.
|
||||
.P
|
||||
If \fIformula\fR is provided, show summary of information about \fIformula\fR\.
|
||||
If a \fIformula\fR or \fIcask\fR is provided, show summary of information about it\.
|
||||
.
|
||||
.TP
|
||||
\fB\-\-analytics\fR
|
||||
@ -360,6 +360,14 @@ Print JSON of all available formulae\.
|
||||
\fB\-v\fR, \fB\-\-verbose\fR
|
||||
Show more verbose analytics data for \fIformula\fR\.
|
||||
.
|
||||
.TP
|
||||
\fB\-\-formula\fR
|
||||
Treat all named arguments as formulae\.
|
||||
.
|
||||
.TP
|
||||
\fB\-\-cask\fR
|
||||
Treat all named arguments as casks\.
|
||||
.
|
||||
.SS "\fBinstall\fR [\fIoptions\fR] \fIformula\fR|\fIcask\fR"
|
||||
Install a \fIformula\fR or \fIcask\fR\. Additional options specific to a \fIformula\fR may be appended to the command\.
|
||||
.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user