From afd7bb88898ab48fa8f4225c0c96858c39f64317 Mon Sep 17 00:00:00 2001 From: Tie Date: Thu, 5 Nov 2020 12:27:22 -0500 Subject: [PATCH] make suggestions --- Library/Homebrew/cmd/autoremove.rb | 10 +++---- Library/Homebrew/cmd/leaves.rb | 3 +- Library/Homebrew/cmd/uninstall.rb | 10 +++---- Library/Homebrew/formula.rb | 12 +++----- Library/Homebrew/test/formula_spec.rb | 43 ++------------------------- 5 files changed, 17 insertions(+), 61 deletions(-) diff --git a/Library/Homebrew/cmd/autoremove.rb b/Library/Homebrew/cmd/autoremove.rb index 384c7ea3de..771fdad0f0 100644 --- a/Library/Homebrew/cmd/autoremove.rb +++ b/Library/Homebrew/cmd/autoremove.rb @@ -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 diff --git a/Library/Homebrew/cmd/leaves.rb b/Library/Homebrew/cmd/leaves.rb index dceb3c0e42..7cb1497367 100644 --- a/Library/Homebrew/cmd/leaves.rb +++ b/Library/Homebrew/cmd/leaves.rb @@ -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 diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index e541425b62..2fadf91c50 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -11,8 +11,6 @@ require "cask/cask_loader" require "uninstall" module Homebrew - extend Uninstall - module_function def uninstall_args @@ -57,10 +55,10 @@ module Homebrew kegs_by_rack = all_kegs.group_by(&:rack) end - uninstall_kegs(kegs_by_rack, - force: args.force?, - ignore_dependencies: args.ignore_dependencies?, - named_args: args.named) + Uninstall.uninstall_kegs(kegs_by_rack, + force: args.force?, + ignore_dependencies: args.ignore_dependencies?, + named_args: args.named) return if casks.blank? diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index e10ca82e6f..5d2dc27735 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -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) diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index f5d785da82..c91b27d04f 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -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