make suggestions

This commit is contained in:
Tie 2020-11-05 12:27:22 -05:00
parent b5d5be3474
commit afd7bb8889
5 changed files with 17 additions and 61 deletions

View File

@ -6,8 +6,6 @@ require "cli/parser"
require "uninstall"
module Homebrew
extend Uninstall
module_function
def autoremove_args
@ -24,7 +22,7 @@ module Homebrew
end
def get_removable_formulae(formulae)
removable_formulae = Formula.installed_non_deps(formulae).reject do |f|
removable_formulae = Formula.installed_formulae_with_no_dependents(formulae).reject do |f|
Tab.for_keg(f.any_installed_keg).installed_on_request
end
@ -42,12 +40,14 @@ module Homebrew
formulae_names = removable_formulae.map(&:full_name).sort
oh1 "Formulae that could be removed"
intent = args.dry_run? ? "could" : "will"
oh1 "Formulae that #{intent} be removed"
puts formulae_names
return if args.dry_run?
puts
kegs_by_rack = removable_formulae.map(&:any_installed_keg).group_by(&:rack)
uninstall_kegs(kegs_by_rack)
Uninstall.uninstall_kegs(kegs_by_rack)
end
end

View File

@ -22,7 +22,6 @@ module Homebrew
def leaves
leaves_args.parse
leaves = Formula.installed_non_deps.map(&:full_name).sort
leaves.each(&method(:puts))
Formula.installed_formulae_with_no_dependents.map(&:full_name).sort.each(&method(:puts))
end
end

View File

@ -11,8 +11,6 @@ require "cask/cask_loader"
require "uninstall"
module Homebrew
extend Uninstall
module_function
def uninstall_args
@ -57,7 +55,7 @@ module Homebrew
kegs_by_rack = all_kegs.group_by(&:rack)
end
uninstall_kegs(kegs_by_rack,
Uninstall.uninstall_kegs(kegs_by_rack,
force: args.force?,
ignore_dependencies: args.ignore_dependencies?,
named_args: args.named)

View File

@ -1515,16 +1515,12 @@ class Formula
end.uniq(&:name)
end
# An array of installed {Formula} that are dependencies of other installed {Formula}
# An array of all installed {Formula} without dependents
# @private
def self.installed_deps(formulae = installed)
formulae.flat_map(&:runtime_formula_dependencies).uniq(&:name)
end
def self.installed_formulae_with_no_dependents(formulae = installed)
return [] if formulae.blank?
# An array of all installed {Formula} that are not dependencies of other installed {Formula}
# @private
def self.installed_non_deps(formulae = installed)
formulae - installed_deps(formulae)
formulae - formulae.flat_map(&:runtime_formula_dependencies)
end
def self.installed_with_alias_path(alias_path)

View File

@ -440,7 +440,7 @@ describe Formula do
end
end
describe "::installed_deps" do
describe "::installed_formulae_with_no_dependents" do
let(:formula_is_dep) do
formula "foo" do
url "foo-1.1"
@ -467,49 +467,12 @@ describe Formula do
specify "without formulae parameter" do
allow(described_class).to receive(:installed).and_return(formulae)
expect(described_class.installed_deps)
.to eq([formula_is_dep])
end
specify "with formulae parameter" do
expect(described_class.installed_deps(formulae))
.to eq([formula_is_dep])
end
end
describe "::installed_non_deps" do
let(:formula_is_dep) do
formula "foo" do
url "foo-1.1"
end
end
let(:formula_with_deps) do
formula "bar" do
url "bar-1.0"
end
end
let(:formulae) do
[
formula_with_deps,
formula_is_dep,
]
end
before do
allow(formula_with_deps).to receive(:runtime_formula_dependencies).and_return([formula_is_dep])
end
specify "without formulae parameter" do
allow(described_class).to receive(:installed).and_return(formulae)
expect(described_class.installed_non_deps)
expect(described_class.installed_formulae_with_no_dependents)
.to eq([formula_with_deps])
end
specify "with formulae parameter" do
expect(described_class.installed_non_deps(formulae))
expect(described_class.installed_formulae_with_no_dependents(formulae))
.to eq([formula_with_deps])
end
end