Pass args
in Install
and Messages
instead of using global args
.
This commit is contained in:
parent
2b33f995f3
commit
f8934c0255
@ -8,6 +8,8 @@ require "socket"
|
||||
require "cli/parser"
|
||||
|
||||
module Homebrew
|
||||
extend Install
|
||||
|
||||
module_function
|
||||
|
||||
def gist_logs_args
|
||||
@ -142,8 +144,8 @@ module Homebrew
|
||||
def gist_logs
|
||||
gist_logs_args.parse
|
||||
|
||||
Install.perform_preinstall_checks(all_fatal: true)
|
||||
Install.perform_build_from_source_checks(all_fatal: true)
|
||||
perform_preinstall_checks(all_fatal: true)
|
||||
perform_build_from_source_checks(all_fatal: true)
|
||||
gistify_logs(args.resolved_formulae.first)
|
||||
end
|
||||
end
|
||||
|
@ -10,10 +10,11 @@ require "cli/parser"
|
||||
require "upgrade"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
extend Install
|
||||
extend Search
|
||||
|
||||
module_function
|
||||
|
||||
def install_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
usage_banner <<~EOS
|
||||
@ -255,17 +256,17 @@ module Homebrew
|
||||
|
||||
return if formulae.empty?
|
||||
|
||||
Install.perform_preinstall_checks
|
||||
perform_preinstall_checks
|
||||
|
||||
formulae.each do |f|
|
||||
Migrator.migrate_if_needed(f)
|
||||
Migrator.migrate_if_needed(f, force: args.force?)
|
||||
install_formula(f)
|
||||
Cleanup.install_formula_clean!(f)
|
||||
end
|
||||
|
||||
check_installed_dependents(args: args)
|
||||
|
||||
Homebrew.messages.display_messages
|
||||
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||
rescue FormulaUnreadableError, FormulaClassUnavailableError,
|
||||
TapFormulaUnreadableError, TapFormulaClassUnavailableError => e
|
||||
# Need to rescue before `FormulaUnavailableError` (superclass of this)
|
||||
|
@ -24,7 +24,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
def migrate
|
||||
migrate_args.parse
|
||||
args = migrate_args.parse
|
||||
|
||||
args.resolved_formulae.each do |f|
|
||||
if f.oldname
|
||||
@ -34,7 +34,7 @@ module Homebrew
|
||||
raise "#{rack} is a symlink" if rack.symlink?
|
||||
end
|
||||
|
||||
migrator = Migrator.new(f)
|
||||
migrator = Migrator.new(f, force: args.force?)
|
||||
migrator.migrate
|
||||
end
|
||||
end
|
||||
|
@ -3,6 +3,7 @@
|
||||
require "formula_installer"
|
||||
require "development_tools"
|
||||
require "messages"
|
||||
require "install"
|
||||
require "reinstall"
|
||||
require "cli/parser"
|
||||
require "cleanup"
|
||||
@ -12,6 +13,8 @@ require "cask/macos"
|
||||
require "upgrade"
|
||||
|
||||
module Homebrew
|
||||
extend Install
|
||||
|
||||
module_function
|
||||
|
||||
def reinstall_args
|
||||
@ -58,7 +61,7 @@ module Homebrew
|
||||
|
||||
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
|
||||
|
||||
Install.perform_preinstall_checks
|
||||
perform_preinstall_checks
|
||||
|
||||
resolved_formulae, casks = args.resolved_formulae_casks
|
||||
resolved_formulae.each do |f|
|
||||
@ -66,14 +69,14 @@ module Homebrew
|
||||
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
|
||||
next
|
||||
end
|
||||
Migrator.migrate_if_needed(f)
|
||||
Migrator.migrate_if_needed(f, force: args.force?)
|
||||
reinstall_formula(f, args: args)
|
||||
Cleanup.install_formula_clean!(f)
|
||||
end
|
||||
|
||||
check_installed_dependents(args: args)
|
||||
|
||||
Homebrew.messages.display_messages
|
||||
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||
|
||||
return if casks.blank?
|
||||
|
||||
|
@ -38,7 +38,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
def update_report
|
||||
update_report_args.parse
|
||||
args = update_report_args.parse
|
||||
|
||||
if !Utils::Analytics.messages_displayed? &&
|
||||
!Utils::Analytics.disabled? &&
|
||||
@ -122,7 +122,7 @@ module Homebrew
|
||||
else
|
||||
hub.dump(updated_formula_report: !args.preinstall?)
|
||||
hub.reporters.each(&:migrate_tap_migration)
|
||||
hub.reporters.each(&:migrate_formula_rename)
|
||||
hub.reporters.each { |r| r.migrate_formula_rename(force: args.force?) }
|
||||
CacheStoreDatabase.use(:descriptions) do |db|
|
||||
DescriptionCacheStore.new(db)
|
||||
.update_from_report!(hub)
|
||||
@ -373,7 +373,7 @@ class Reporter
|
||||
end
|
||||
end
|
||||
|
||||
def migrate_formula_rename
|
||||
def migrate_formula_rename(force:)
|
||||
Formula.installed.each do |formula|
|
||||
next unless Migrator.needs_migration?(formula)
|
||||
|
||||
@ -397,7 +397,7 @@ class Reporter
|
||||
next
|
||||
end
|
||||
|
||||
Migrator.migrate_if_needed(f)
|
||||
Migrator.migrate_if_needed(f, force: force)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -9,6 +9,8 @@ require "cask/utils"
|
||||
require "cask/macos"
|
||||
|
||||
module Homebrew
|
||||
extend Install
|
||||
|
||||
module_function
|
||||
|
||||
def upgrade_args
|
||||
@ -77,7 +79,7 @@ module Homebrew
|
||||
def upgrade_outdated_formulae(formulae)
|
||||
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
|
||||
|
||||
Install.perform_preinstall_checks
|
||||
perform_preinstall_checks
|
||||
|
||||
if formulae.blank?
|
||||
outdated = Formula.installed.select do |f|
|
||||
@ -129,7 +131,7 @@ module Homebrew
|
||||
|
||||
check_installed_dependents(args: args)
|
||||
|
||||
Homebrew.messages.display_messages
|
||||
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||
end
|
||||
|
||||
def upgrade_outdated_casks(casks)
|
||||
|
@ -21,6 +21,7 @@ require "cmd/install"
|
||||
require "find"
|
||||
|
||||
class FormulaInstaller
|
||||
include Homebrew::Install
|
||||
include FormulaCellarChecks
|
||||
extend Predicable
|
||||
|
||||
@ -239,9 +240,7 @@ class FormulaInstaller
|
||||
lock
|
||||
|
||||
start_time = Time.now
|
||||
if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
|
||||
Homebrew::Install.perform_build_from_source_checks
|
||||
end
|
||||
perform_build_from_source_checks if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
|
||||
|
||||
# not in initialize so upgrade can unlink the active keg before calling this
|
||||
# function but after instantiating this class so that it can avoid having to
|
||||
|
@ -7,8 +7,6 @@ require "development_tools"
|
||||
|
||||
module Homebrew
|
||||
module Install
|
||||
module_function
|
||||
|
||||
def check_cpu
|
||||
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
|
||||
|
||||
@ -40,11 +38,11 @@ module Homebrew
|
||||
end
|
||||
|
||||
def check_cc_argv
|
||||
return unless Homebrew.args.cc
|
||||
return unless (cc = args.cc)
|
||||
|
||||
@checks ||= Diagnostic::Checks.new
|
||||
opoo <<~EOS
|
||||
You passed `--cc=#{Homebrew.args.cc}`.
|
||||
You passed `--cc=#{cc}`.
|
||||
#{@checks.please_create_pull_requests}
|
||||
EOS
|
||||
end
|
||||
|
@ -20,9 +20,9 @@ class Messages
|
||||
@install_times.push(formula: f.name, time: elapsed_time)
|
||||
end
|
||||
|
||||
def display_messages
|
||||
def display_messages(display_times: false)
|
||||
display_caveats
|
||||
display_install_times if Homebrew.args.display_times?
|
||||
display_install_times if display_times
|
||||
end
|
||||
|
||||
def display_caveats
|
||||
|
@ -97,18 +97,18 @@ class Migrator
|
||||
true
|
||||
end
|
||||
|
||||
def self.migrate_if_needed(formula)
|
||||
def self.migrate_if_needed(formula, force:)
|
||||
return unless Migrator.needs_migration?(formula)
|
||||
|
||||
begin
|
||||
migrator = Migrator.new(formula)
|
||||
migrator = Migrator.new(formula, force: force)
|
||||
migrator.migrate
|
||||
rescue => e
|
||||
onoe e
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(formula, force: Homebrew.args.force?)
|
||||
def initialize(formula, force: false)
|
||||
@oldname = formula.oldname
|
||||
@newname = formula.name
|
||||
raise MigratorNoOldnameError, formula unless oldname
|
||||
|
@ -72,27 +72,20 @@ describe Messages do
|
||||
end
|
||||
end
|
||||
|
||||
# Homebrew.args OpenStruct usage cannot use verified doubles.
|
||||
# rubocop:disable RSpec/VerifiedDoubles
|
||||
context "when the --display-times argument is present" do
|
||||
before do
|
||||
allow(Homebrew).to receive(:args).and_return \
|
||||
double(display_times?: true, flags_only: ["--display-times"])
|
||||
end
|
||||
|
||||
context "when install_times is empty" do
|
||||
it "doesn't print any output" do
|
||||
expect { messages.display_messages }.not_to output.to_stdout
|
||||
context "when the `display_times` argument is true" do
|
||||
context "when `install_times` is empty" do
|
||||
it "doesn't print anything" do
|
||||
expect { messages.display_messages(display_times: true) }.not_to output.to_stdout
|
||||
end
|
||||
end
|
||||
|
||||
context "when install_times is present" do
|
||||
context "when `install_times` is present" do
|
||||
before do
|
||||
messages.formula_installed(test_formula, elapsed_time)
|
||||
end
|
||||
|
||||
it "prints installation times" do
|
||||
expect { messages.display_messages }.to output(
|
||||
expect { messages.display_messages(display_times: true) }.to output(
|
||||
<<~EOS,
|
||||
==> Installation times
|
||||
foo 1.100 s
|
||||
@ -102,15 +95,10 @@ describe Messages do
|
||||
end
|
||||
end
|
||||
|
||||
context "when the --display-times argument isn't present" do
|
||||
before do
|
||||
allow(Homebrew).to receive(:args).and_return(double(display_times?: false))
|
||||
end
|
||||
|
||||
context "when the `display_times` argument isn't specified" do
|
||||
it "doesn't print installation times" do
|
||||
expect { messages.display_messages }.not_to output.to_stdout
|
||||
end
|
||||
end
|
||||
# rubocop:enable RSpec/VerifiedDoubles
|
||||
end
|
||||
end
|
||||
|
@ -26,7 +26,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
formulae_to_install.each do |f|
|
||||
Migrator.migrate_if_needed(f)
|
||||
Migrator.migrate_if_needed(f, force: args.force?)
|
||||
begin
|
||||
upgrade_formula(f, args: args)
|
||||
Cleanup.install_formula_clean!(f)
|
||||
|
Loading…
x
Reference in New Issue
Block a user