Skip to content

Commit

Permalink
Merge pull request #10134 from MikeMcQuaid/unbottled-tweaks
Browse files Browse the repository at this point in the history
dev-cmd/unbottled: improve output.
  • Loading branch information
MikeMcQuaid committed Dec 28, 2020
2 parents 55054a1 + d20b946 commit 20ff74a
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions Library/Homebrew/dev-cmd/unbottled.rb
Expand Up @@ -41,8 +41,8 @@ def unbottled
raise UsageError, "cannot specify `<formula>` and `--total`."
end

formulae, all_formulae, sort, formula_installs =
formulae_all_sort_installs_from_args(args)
formulae, all_formulae, formula_installs =
formulae_all_installs_from_args(args)
deps_hash, uses_hash = deps_uses_from_formulae(all_formulae)

if args.dependents?
Expand All @@ -65,18 +65,19 @@ def unbottled
else
["installs", formula_installs]
end
output_unbottled(sort, formulae, deps_hash, noun, hash)

output_unbottled(formulae, deps_hash, noun, hash, args.named.present?)
end

def formulae_all_sort_installs_from_args(args)
def formulae_all_installs_from_args(args)
if args.named.present?
formulae = all_formulae = args.named.to_formulae
elsif args.total?
formulae = all_formulae = Formula.to_a
elsif args.dependents?
formulae = all_formulae = Formula.to_a

sort = " (sorted by installs in the last 90 days)"
@sort = " (sorted by installs in the last 90 days)"
else
formula_installs = {}

Expand All @@ -101,12 +102,12 @@ def formulae_all_sort_installs_from_args(args)
nil
end
end.compact
sort = " (sorted by installs in the last 90 days)"
@sort = " (sorted by installs in the last 90 days)"

all_formulae = Formula
end

[formulae, all_formulae, sort, formula_installs]
[formulae, all_formulae, formula_installs]
end

def deps_uses_from_formulae(all_formulae)
Expand Down Expand Up @@ -146,30 +147,54 @@ def output_total(formulae)
puts "#{unbottled_formulae}/#{formulae.length} remaining."
end

def output_unbottled(sort, formulae, deps_hash, noun, hash)
ohai "Unbottled :#{@bottle_tag} dependencies#{sort}"
def output_unbottled(formulae, deps_hash, noun, hash, any_named_args)
ohai ":#{@bottle_tag} bottle status#{@sort}"
any_found = T.let(false, T::Boolean)

formulae.each do |f|
next if f.bottle_specification.tag?(@bottle_tag)
name = f.name.downcase
if f.bottle_specification.tag?(@bottle_tag)
puts "#{Tty.bold}#{Tty.green}#{name}#{Tty.reset}: already bottled" if any_named_args
next
end

requirement_classes = f.recursive_requirements.map(&:class)
if @bottle_tag.to_s.end_with?("_linux")
if requirement_classes.include?(MacOSRequirement)
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires macOS" if any_named_args
next
end
elsif requirement_classes.include?(LinuxRequirement)
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires Linux" if any_named_args
next
end

if f.bottle_unneeded? || f.bottle_disabled?
reason = if f.bottle_unneeded?
"unneeded"
else
"disabled"
end
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: bottle #{reason}" if any_named_args
next
end

deps = Array(deps_hash[f.name]).reject do |dep|
dep.bottle_specification.tag?(@bottle_tag) || dep.bottle_unneeded?
end

if deps.blank?
next if f.bottle_unneeded?

count = " (#{hash[f.name]} #{noun})" if noun
puts "#{f.name}#{count}: ready to bottle"
puts "#{Tty.bold}#{Tty.green}#{name}#{Tty.reset}#{count}: ready to bottle"
next
end

any_found ||= true
count = " (#{hash[f.name]} #{noun})" if noun
puts "#{f.name}#{count}: #{deps.join(" ")}"
puts "#{Tty.bold}#{Tty.yellow}#{name}#{Tty.reset}#{count}: unbottled deps: #{deps.join(" ")}"
end
return if any_found
return if any_named_args

puts "No unbottled dependencies found!"
end
Expand Down

0 comments on commit 20ff74a

Please sign in to comment.