From 75a692d08b459138e1204fcd6a66f126f95437a3 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 2 Aug 2020 03:22:22 +0200 Subject: [PATCH] Make `ohai`, `oh1` and `odebug` use `#debug?` and `verbose?` of the current object when possible. --- Library/Homebrew/formula_installer.rb | 8 ++++---- Library/Homebrew/utils.rb | 28 ++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 8911a2b5a1..30d7d2c292 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -939,7 +939,7 @@ class FormulaInstaller log.mkpath if formula.plist.include? log.to_s rescue Exception => e # rubocop:disable Lint/RescueException onoe "Failed to install plist file" - ohai e, e.backtrace if debug? + odebug e, e.backtrace Homebrew.failed = true end @@ -949,7 +949,7 @@ class FormulaInstaller onoe "Failed to fix install linkage" puts "The formula built, but you may encounter issues using it or linking other" puts "formulae against it." - ohai e, e.backtrace if debug? + odebug e, e.backtrace Homebrew.failed = true @show_summary_heading = true end @@ -960,7 +960,7 @@ class FormulaInstaller rescue Exception => e # rubocop:disable Lint/RescueException opoo "The cleaning step did not complete successfully" puts "Still, the installation was successful, so we will link it into your prefix" - ohai e, e.backtrace if debug? + odebug e, e.backtrace Homebrew.failed = true @show_summary_heading = true end @@ -996,7 +996,7 @@ class FormulaInstaller rescue Exception => e # rubocop:disable Lint/RescueException opoo "The post-install step did not complete successfully" puts "You can try again using `brew postinstall #{formula.full_name}`" - ohai e, e.backtrace if debug? || Homebrew::EnvConfig.developer? + odebug e, e.backtrace, always_display: Homebrew::EnvConfig.developer? Homebrew.failed = true @show_summary_heading = true end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 254ac11ea1..fce6709031 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -86,7 +86,13 @@ module Kernel end def ohai_title(title) - title = Tty.truncate(title) if $stdout.tty? && !Homebrew.args.verbose? + verbose = if respond_to?(:verbose?) + verbose? + else + Homebrew.args.verbose? + end + + title = Tty.truncate(title) if $stdout.tty? && !verbose Formatter.headline(title, color: :blue) end @@ -95,15 +101,27 @@ module Kernel puts sput end - def odebug(title, *sput) - return unless Homebrew.args.debug? + def odebug(title, *sput, always_display: false) + debug = if respond_to?(:debug?) + debug? + else + Homebrew.args.debug? + end + + return unless debug || always_display puts Formatter.headline(title, color: :magenta) puts sput unless sput.empty? end - def oh1(title, options = {}) - title = Tty.truncate(title) if $stdout.tty? && !Homebrew.args.verbose? && options.fetch(:truncate, :auto) == :auto + def oh1(title, truncate: :auto) + verbose = if respond_to?(:verbose?) + verbose? + else + Homebrew.args.verbose? + end + + title = Tty.truncate(title) if $stdout.tty? && !verbose && truncate == :auto puts Formatter.headline(title, color: :green) end