brew/Library/Homebrew/cmd/reinstall.rb

89 lines
3.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-10-31 20:10:08 -05:00
require "formula_installer"
require "development_tools"
require "messages"
require "install"
require "reinstall"
2019-04-17 18:25:08 +09:00
require "cli/parser"
require "cleanup"
require "cask/cmd"
require "cask/utils"
require "cask/macos"
require "upgrade"
2013-02-17 13:23:41 +00:00
module Homebrew
extend Install
2016-09-26 01:44:51 +02:00
module_function
def reinstall_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`reinstall` [<options>] <formula>
Uninstall and then install <formula> using the same options it was originally
installed with, plus any appended brew formula options.
Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the
2019-08-06 13:23:19 -04:00
reinstalled formulae or, every 30 days, for all formulae.
EOS
switch :debug,
2019-04-30 08:44:35 +01:00
description: "If brewing fails, open an interactive debugging session with access to IRB "\
2019-08-06 14:22:24 -04:00
"or a shell inside the temporary build directory."
switch "-s", "--build-from-source",
2019-04-30 08:44:35 +01:00
description: "Compile <formula> from source even if a bottle is available."
switch "-i", "--interactive",
description: "Download and patch <formula>, then open a shell. This allows the user to "\
"run `./configure --help` and otherwise determine how to turn the software "\
"package into a Homebrew package."
switch "--force-bottle",
2019-04-30 08:44:35 +01:00
description: "Install from a bottle if it exists for the current or newest version of "\
"macOS, even if it would not normally be used for installation."
switch "--keep-tmp",
description: "Retain the temporary files created during installation."
switch "-f", "--force",
2019-04-30 08:44:35 +01:00
description: "Install without checking for previously installed keg-only or "\
"non-migrated versions."
switch :verbose,
2019-04-30 08:44:35 +01:00
description: "Print the verification and postinstall steps."
switch "--display-times",
env: :display_install_times,
2019-04-30 08:44:35 +01:00
description: "Print install times for each formula at the end of the run."
conflicts "--build-from-source", "--force-bottle"
formula_options
min_named :formula
end
end
2013-02-17 13:23:41 +00:00
def reinstall
args = reinstall_args.parse
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
perform_preinstall_checks
2020-06-30 12:08:03 -04:00
resolved_formulae, casks = args.resolved_formulae_casks
resolved_formulae.each do |f|
2016-09-05 22:40:08 +03:00
if f.pinned?
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
next
end
Migrator.migrate_if_needed(f, force: args.force?)
reinstall_formula(f, args: args)
Cleanup.install_formula_clean!(f)
2016-09-05 22:40:08 +03:00
end
check_installed_dependents(args: args)
Homebrew.messages.display_messages(display_times: args.display_times?)
2020-07-03 10:33:38 -04:00
return if casks.blank?
2020-06-30 12:21:21 -04:00
reinstall_cmd = Cask::Cmd::Reinstall.new(casks)
reinstall_cmd.verbose = args.verbose?
reinstall_cmd.force = args.force?
reinstall_cmd.run
end
2013-02-17 13:23:41 +00:00
end