Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn developers when uninstalling a dependency #1498

Merged
merged 4 commits into from
Nov 15, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
uninstall: clean up warnings
  • Loading branch information
alyssais committed Nov 14, 2016
commit c77040b346fe95e09a18ba7268548d72be3cc6cb
72 changes: 50 additions & 22 deletions Library/Homebrew/cmd/uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,64 @@ def check_for_dependents(kegs)
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put all the shared stuff between the two messages into a class so it can be re-used between both of them. It's a bit longer, but I think much cleaner now.

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)
Expand Down