Merge pull request #8893 from whoiswillma/william/integrate-brew-info
cmd/info: Add support for casks in brew info
This commit is contained in:
commit
60046ac41c
@ -39,6 +39,22 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_formulae_to_casks(method: nil, only: nil)
|
||||||
|
@to_formulae_to_casks ||= {}
|
||||||
|
@to_formulae_to_casks[[method, only]] = to_formulae_and_casks(method: method, only: only)
|
||||||
|
.partition { |o| o.is_a?(Formula) }
|
||||||
|
.map(&:freeze).freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_formulae_and_casks_and_unavailable(method: nil)
|
||||||
|
@to_formulae_casks_unknowns ||= {}
|
||||||
|
@to_formulae_casks_unknowns[method] = downcased_unique_named.map do |name|
|
||||||
|
load_formula_or_cask(name, method: method)
|
||||||
|
rescue FormulaOrCaskUnavailableError => e
|
||||||
|
e
|
||||||
|
end.uniq.freeze
|
||||||
|
end
|
||||||
|
|
||||||
def load_formula_or_cask(name, only: nil, method: nil)
|
def load_formula_or_cask(name, only: nil, method: nil)
|
||||||
if only != :cask
|
if only != :cask
|
||||||
begin
|
begin
|
||||||
@ -81,9 +97,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_resolved_formulae_to_casks(only: nil)
|
def to_resolved_formulae_to_casks(only: nil)
|
||||||
@to_resolved_formulae_to_casks ||= to_formulae_and_casks(method: :resolve, only: only)
|
to_formulae_to_casks(method: :resolve, only: only)
|
||||||
.partition { |o| o.is_a?(Formula) }
|
|
||||||
.map(&:freeze).freeze
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert named arguments to `Tap`, `Formula` or `Cask` objects.
|
# Convert named arguments to `Tap`, `Formula` or `Cask` objects.
|
||||||
|
|||||||
@ -65,27 +65,26 @@ module Homebrew
|
|||||||
def info
|
def info
|
||||||
args = info_args.parse
|
args = info_args.parse
|
||||||
|
|
||||||
if args.days.present? && !VALID_DAYS.include?(args.days)
|
if args.analytics?
|
||||||
raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}"
|
if args.days.present? && !VALID_DAYS.include?(args.days)
|
||||||
end
|
raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}"
|
||||||
|
|
||||||
if args.category.present?
|
|
||||||
if args.named.present? && !VALID_FORMULA_CATEGORIES.include?(args.category)
|
|
||||||
raise UsageError, "--category must be one of #{VALID_FORMULA_CATEGORIES.join(", ")} when querying formulae"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
unless VALID_CATEGORIES.include?(args.category)
|
if args.category.present?
|
||||||
raise UsageError, "--category must be one of #{VALID_CATEGORIES.join(", ")}"
|
if args.named.present? && !VALID_FORMULA_CATEGORIES.include?(args.category)
|
||||||
|
raise UsageError, "--category must be one of #{VALID_FORMULA_CATEGORIES.join(", ")} when querying formulae"
|
||||||
|
end
|
||||||
|
|
||||||
|
unless VALID_CATEGORIES.include?(args.category)
|
||||||
|
raise UsageError, "--category must be one of #{VALID_CATEGORIES.join(", ")}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if args.json
|
|
||||||
raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
|
|
||||||
raise FormulaUnspecifiedError if !(args.all? || args.installed?) && args.no_named?
|
|
||||||
|
|
||||||
|
print_analytics(args: args)
|
||||||
|
elsif args.json
|
||||||
print_json(args: args)
|
print_json(args: args)
|
||||||
elsif args.github?
|
elsif args.github?
|
||||||
raise FormulaUnspecifiedError if args.no_named?
|
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.map { |f| github_info(f) })
|
||||||
else
|
else
|
||||||
@ -93,7 +92,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_info(args:)
|
def print_analytics(args:)
|
||||||
if args.no_named?
|
if args.no_named?
|
||||||
if args.analytics?
|
if args.analytics?
|
||||||
Utils::Analytics.output(args: args)
|
Utils::Analytics.output(args: args)
|
||||||
@ -101,40 +100,90 @@ module Homebrew
|
|||||||
count = Formula.racks.length
|
count = Formula.racks.length
|
||||||
puts "#{count} #{"keg".pluralize(count)}, #{HOMEBREW_CELLAR.dup.abv}"
|
puts "#{count} #{"keg".pluralize(count)}, #{HOMEBREW_CELLAR.dup.abv}"
|
||||||
end
|
end
|
||||||
else
|
|
||||||
args.named.each_with_index do |f, i|
|
return
|
||||||
puts unless i.zero?
|
end
|
||||||
begin
|
|
||||||
formula = Formulary.factory(f)
|
args.named.to_formulae_and_casks_and_unavailable.each_with_index do |obj, i|
|
||||||
if args.analytics?
|
puts unless i.zero?
|
||||||
Utils::Analytics.formula_output(formula, args: args)
|
|
||||||
else
|
case obj
|
||||||
info_formula(formula, args: args)
|
when Formula
|
||||||
end
|
Utils::Analytics.formula_output(obj, args: args)
|
||||||
rescue FormulaUnavailableError => e
|
when Cask::Cask
|
||||||
if args.analytics?
|
Utils::Analytics.cask_output(obj, args: args)
|
||||||
Utils::Analytics.output(filter: f, args: args)
|
when FormulaOrCaskUnavailableError
|
||||||
next
|
Utils::Analytics.output(filter: obj.name, args: args)
|
||||||
end
|
else
|
||||||
ofail e.message
|
raise
|
||||||
# No formula with this name, try a missing formula lookup
|
|
||||||
if (reason = MissingFormula.reason(f, show_info: true))
|
|
||||||
$stderr.puts reason
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_json(args:)
|
def print_info(args:)
|
||||||
ff = if args.all?
|
args.named.to_formulae_and_casks_and_unavailable.each_with_index do |obj, i|
|
||||||
Formula.sort
|
puts unless i.zero?
|
||||||
elsif args.installed?
|
|
||||||
Formula.installed.sort
|
case obj
|
||||||
else
|
when Formula
|
||||||
args.named.to_formulae
|
info_formula(obj, args: args)
|
||||||
|
when Cask::Cask
|
||||||
|
info_cask(obj, args: args)
|
||||||
|
when FormulaOrCaskUnavailableError
|
||||||
|
ofail obj.message
|
||||||
|
# No formula with this name, try a missing formula lookup
|
||||||
|
if (reason = MissingFormula.reason(obj.name, show_info: true))
|
||||||
|
$stderr.puts reason
|
||||||
|
end
|
||||||
|
else
|
||||||
|
raise
|
||||||
|
end
|
||||||
end
|
end
|
||||||
json = ff.map(&:to_hash)
|
end
|
||||||
|
|
||||||
|
def json_version(version)
|
||||||
|
version_hash = {
|
||||||
|
true => :default,
|
||||||
|
"v1" => :v1,
|
||||||
|
"v2" => :v2,
|
||||||
|
}
|
||||||
|
|
||||||
|
raise UsageError, "invalid JSON version: #{version}" unless version_hash.include?(version)
|
||||||
|
|
||||||
|
version_hash[version]
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_json(args:)
|
||||||
|
raise FormulaOrCaskUnspecifiedError if !(args.all? || args.installed?) && args.no_named?
|
||||||
|
|
||||||
|
json = case json_version(args.json)
|
||||||
|
when :v1, :default
|
||||||
|
formulae = if args.all?
|
||||||
|
Formula.sort
|
||||||
|
elsif args.installed?
|
||||||
|
Formula.installed.sort
|
||||||
|
else
|
||||||
|
args.named.to_formulae
|
||||||
|
end
|
||||||
|
|
||||||
|
formulae.map(&:to_hash)
|
||||||
|
when :v2
|
||||||
|
formulae, casks = if args.all?
|
||||||
|
[Formula.sort, Cask::Cask.to_a.sort_by(&:full_name)]
|
||||||
|
elsif args.installed?
|
||||||
|
[Formula.installed.sort, Cask::Caskroom.casks.sort_by(&:full_name)]
|
||||||
|
else
|
||||||
|
args.named.to_formulae_to_casks
|
||||||
|
end
|
||||||
|
|
||||||
|
{
|
||||||
|
"formulae" => formulae.map(&:to_hash),
|
||||||
|
"casks" => casks.map(&:to_h),
|
||||||
|
}
|
||||||
|
else
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
|
||||||
puts JSON.generate(json)
|
puts JSON.generate(json)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -275,4 +324,10 @@ module Homebrew
|
|||||||
|
|
||||||
"#{dep.name} #{dep.option_tags.map { |o| "--#{o}" }.join(" ")}"
|
"#{dep.name} #{dep.option_tags.map { |o| "--#{o}" }.join(" ")}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def info_cask(cask, args:)
|
||||||
|
require "cask/cmd/info"
|
||||||
|
|
||||||
|
Cask::Cmd::Info.info(cask)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -18,6 +18,15 @@ describe "brew info", :integration_test do
|
|||||||
.and not_to_output.to_stderr
|
.and not_to_output.to_stderr
|
||||||
.and be_a_success
|
.and be_a_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "prints as json with the --json=v2 flag" do
|
||||||
|
setup_test_formula "testball"
|
||||||
|
|
||||||
|
expect { brew "info", "testball", "--json=v2" }
|
||||||
|
.to output(a_json_string).to_stdout
|
||||||
|
.and not_to_output.to_stderr
|
||||||
|
.and be_a_success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Homebrew do
|
describe Homebrew do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user