From 3c310b2e3dd7805b04f48507c65c2c0a856c2aa2 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 11 Nov 2016 20:08:26 +0000 Subject: Warn developers when uninstalling a dependency Suggested in #1084. Made the existing warning output entirely to STDERR, because previously the first line went to STDERR and subsequent ones went to STDOUT. --- Library/Homebrew/cmd/uninstall.rb | 45 +++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'Library/Homebrew/cmd') diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index d9e6a7377..d172b0238 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -28,10 +28,8 @@ module Homebrew ARGV.kegs.group_by(&:rack) end - if should_check_for_dependents? - all_kegs = kegs_by_rack.values.flatten(1) - return if check_for_dependents all_kegs - end + handle_unsatisfied_dependents(kegs_by_rack) + return if Homebrew.failed? kegs_by_rack.each do |rack, kegs| if ARGV.force? @@ -78,28 +76,47 @@ module Homebrew end end - def should_check_for_dependents? - # --ignore-dependencies, to be consistent with install - return false if ARGV.include?("--ignore-dependencies") - return false if ARGV.homebrew_developer? - true + def handle_unsatisfied_dependents(kegs_by_rack) + return if ARGV.include?("--ignore-dependencies") + + all_kegs = kegs_by_rack.values.flatten(1) + check_for_dependents all_kegs end def check_for_dependents(kegs) return false unless result = Keg.find_some_installed_dependents(kegs) - requireds, dependents = result + if ARGV.homebrew_developer? + dependents_output_for_developers(*result) + else + dependents_output_for_nondevelopers(*result) + end + + true + end + def dependents_output_for_developers(requireds, dependents) + msg = requireds.join(", ") + msg << (requireds.count == 1 ? " is" : " are") + msg << " required by #{dependents.join(", ")}, which " + msg << (dependents.count == 1 ? "is" : "are") + msg << " currently installed." + msg << "\nYou can silence this warning with " + msg << "`brew uninstall --ignore-dependencies " + msg << "#{requireds.map(&:name).join(" ")}`." + opoo msg + end + + def dependents_output_for_nondevelopers(requireds, dependents) msg = "Refusing to uninstall #{requireds.join(", ")} because " msg << (requireds.count == 1 ? "it is" : "they are") msg << " required by #{dependents.join(", ")}, which " msg << (dependents.count == 1 ? "is" : "are") msg << " currently installed." + msg << "\nYou can override this and force removal with " + msg << "`brew uninstall --ignore-dependencies " + msg << "#{requireds.map(&:name).join(" ")}`." ofail msg - print "You can override this and force removal with " - puts "`brew uninstall --ignore-dependencies #{requireds.map(&:name).join(" ")}`." - - true end def rm_pin(rack) -- cgit v1.2.3 From c77040b346fe95e09a18ba7268548d72be3cc6cb Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 14 Nov 2016 13:09:40 +0000 Subject: uninstall: clean up warnings --- Library/Homebrew/cmd/uninstall.rb | 72 +++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 22 deletions(-) (limited to 'Library/Homebrew/cmd') diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index d172b0238..c1923ebf4 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -87,36 +87,64 @@ module Homebrew return false unless result = Keg.find_some_installed_dependents(kegs) if ARGV.homebrew_developer? - dependents_output_for_developers(*result) + DeveloperDependentsMessage.new(*result).output else - dependents_output_for_nondevelopers(*result) + NondeveloperDependentsMessage.new(*result).output end true end - def dependents_output_for_developers(requireds, dependents) - msg = requireds.join(", ") - msg << (requireds.count == 1 ? " is" : " are") - msg << " required by #{dependents.join(", ")}, which " - msg << (dependents.count == 1 ? "is" : "are") - msg << " currently installed." - msg << "\nYou can silence this warning with " - msg << "`brew uninstall --ignore-dependencies " - msg << "#{requireds.map(&:name).join(" ")}`." - opoo msg + class DependentsMessage + attr :reqs, :deps + + def initialize(requireds, dependents) + @reqs = requireds + @deps = dependents + end + + protected + + def is(items) + items.count == 1 ? "is" : "are" + end + + def it(items) + items.count == 1 ? "it" : "they" + end + + def list(items) + items.join(", ") + end + + def sample_command + "brew uninstall --ignore-dependencies #{list reqs.map(&:name)}" + end + + def is_required_by_deps + "#{is reqs} required by #{list deps}, which #{is deps} currently installed" + end end - def dependents_output_for_nondevelopers(requireds, dependents) - msg = "Refusing to uninstall #{requireds.join(", ")} because " - msg << (requireds.count == 1 ? "it is" : "they are") - msg << " required by #{dependents.join(", ")}, which " - msg << (dependents.count == 1 ? "is" : "are") - msg << " currently installed." - msg << "\nYou can override this and force removal with " - msg << "`brew uninstall --ignore-dependencies " - msg << "#{requireds.map(&:name).join(" ")}`." - ofail msg + class DeveloperDependentsMessage < DependentsMessage + def output + opoo <<-EOS.undent + #{list reqs} #{is_required_by_deps}. + You can silence this warning with: + #{sample_command} + EOS + end + end + + class NondeveloperDependentsMessage < DependentsMessage + def output + ofail <<-EOS.undent + Refusing to uninstall #{list reqs} + because #{it reqs} #{is_required_by_deps}. + You can override this and force removal with: + #{sample_command} + EOS + end end def rm_pin(rack) -- cgit v1.2.3 From ca3562645c30b86da5057cf2f8de9974c4a18413 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 14 Nov 2016 13:39:17 +0000 Subject: uninstall: style fixes Works around Rubycop not liking method names that start with `is_` by changing convention from singular to plural. I think it's better that way anyway. --- Library/Homebrew/cmd/uninstall.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Library/Homebrew/cmd') diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index c1923ebf4..34695bd1c 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -96,7 +96,7 @@ module Homebrew end class DependentsMessage - attr :reqs, :deps + attr_reader :reqs, :deps def initialize(requireds, dependents) @reqs = requireds @@ -105,11 +105,11 @@ module Homebrew protected - def is(items) + def are(items) items.count == 1 ? "is" : "are" end - def it(items) + def they(items) items.count == 1 ? "it" : "they" end @@ -121,15 +121,15 @@ module Homebrew "brew uninstall --ignore-dependencies #{list reqs.map(&:name)}" end - def is_required_by_deps - "#{is reqs} required by #{list deps}, which #{is deps} currently installed" + def are_required_by_deps + "#{are reqs} required by #{list deps}, which #{are deps} currently installed" end end class DeveloperDependentsMessage < DependentsMessage def output opoo <<-EOS.undent - #{list reqs} #{is_required_by_deps}. + #{list reqs} #{are_required_by_deps}. You can silence this warning with: #{sample_command} EOS @@ -140,7 +140,7 @@ module Homebrew def output ofail <<-EOS.undent Refusing to uninstall #{list reqs} - because #{it reqs} #{is_required_by_deps}. + because #{they reqs} #{are_required_by_deps}. You can override this and force removal with: #{sample_command} EOS -- cgit v1.2.3