brew/Library/Homebrew/cmd/reinstall.rb
Samuel John 43fc7423d7 brew reinstall: Is able to work for all formulae
... and not just installed ones. Of course, strictly speaking,
reinstalling not-yet-installed formulae makes semantically little
sense, but the big win is that we can tell people (after we have
resolved an issue) to `brew reinstall <formula>` and even if a user
has removed that formula in the meantime, reinstall will do the right
thing. Basically adding --force to uninstall. I think this makes
reinstall more robust.
2013-08-21 20:18:55 +02:00

29 lines
933 B
Ruby

require 'cmd/uninstall'
require 'cmd/install'
module Homebrew extend self
def reinstall
# At first save the named formulae and remove them from ARGV
named = ARGV.named
ARGV.delete_if { |arg| named.include? arg }
# We add --force because then uninstall always succeeds and so reinstall
# works for formulae not yet installed.
ARGV << "--force"
clean_ARGV = ARGV.clone
# Add the used_options for each named formula separately so
# that the options apply to the right formula.
named.each do |name|
ARGV.replace(clean_ARGV)
ARGV << name
tab = Tab.for_name(name)
tab.used_options.each { |option| ARGV << option.to_s }
ARGV << '--build-bottle' if tab.built_as_bottle
# Todo: Be as smart as upgrade to restore the old state if reinstall fails.
self.uninstall
oh1 "Reinstalling #{name} #{ARGV.options_only*' '}"
self.install
end
end
end