Module: Utils::Output::Mixin Private
- Extended by:
- T::Helpers
- Included in:
- AbstractDownloadStrategy, Build, BuildError, CPAN, Cask::Artifact::AbstractArtifact, Cask::Artifact::AbstractArtifact, Cask::Audit, Cask::Auditor, Cask::Cask, Cask::CaskLoader, Cask::CaskLoader::ILoader, Cask::Caskroom, Cask::DSL, Cask::Info, Cask::Installer, Cask::Installer, Cask::List, Cask::Metadata, Cask::Migrator, Cask::Pkg, Cask::Quarantine, Cask::Reinstall, Cask::Staged, Cask::Uninstall, Cask::Upgrade, Cask::Utils, Cleaner, Downloadable, ExternalPatch, Formula, Formula, FormulaInstaller, FormulaVersions, Formulary, Formulary, Formulary::FormulaLoader, Formulary::FromBottleLoader, GitHub, GitHub::API, GitHub::API::Error, GitHubPackages, GitHubReleases, Homebrew, Homebrew::API, Homebrew::AbstractCommand, Homebrew::Aliases, Homebrew::Aliases::Alias, Homebrew::Assertions, Homebrew::Attestation, Homebrew::Bundle::Commands::Exec, Homebrew::Bundle::FormulaDumper, Homebrew::Bundle::Remover, Homebrew::Bundle::WhalebrewDumper, Homebrew::Bundle::WhalebrewInstaller, Homebrew::CLI::NamedArgs, Homebrew::CLI::Parser, Homebrew::Cleanup, Homebrew::Cleanup, Homebrew::Completions, Homebrew::Diagnostic, Homebrew::Diagnostic::Checks, Homebrew::DownloadQueue, Homebrew::EnvConfig, Homebrew::EnvConfig, Homebrew::FormulaAuditor, Homebrew::FormulaCreator, Homebrew::Help, Homebrew::Install, Homebrew::Livecheck, Homebrew::MissingFormula, Homebrew::Reinstall, Homebrew::RetryableDownload, Homebrew::Search, Homebrew::Services::Cli, Homebrew::Services::Commands::List, Homebrew::Services::FormulaWrapper, Homebrew::Services::System, Homebrew::Style, Homebrew::Uninstall, Homebrew::Uninstall::DependentsMessage, Homebrew::UnversionedCaskChecker, Homebrew::Upgrade, Keg, Language::Node, Language::Python, LinkageChecker, LockFile, Messages, Migrator, Migrator, Mktemp, OS::Mac::Readall::ClassMethods, Pathname, PyPI, PyPI::Package, Readall, Repology, Reporter, ReporterHub, Requirement, Resource, SBOM, Sandbox, StringInreplaceExtension, Superenv, SystemCommand::Result, Tap, Tap, Time, UnpackStrategy, UnpackStrategy, UnpackStrategy::Dmg::Bom, Analytics, Backtrace, Gzip, Link, Utils::Output, Svn, Tar
- Defined in:
- utils/output.rb
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Instance Method Summary collapse
- #odebug(title, *sput, always_display: false) ⇒ void private
-
#odeprecated(method, replacement = nil, disable: false, disable_on: nil, disable_for_developers: true, caller: send(:caller)) ⇒ void
private
Output a deprecation warning/error message.
-
#odie(error) ⇒ T.noreturn
Print an error message and fail immediately.
- #odisabled(method, replacement = nil, disable_on: nil, disable_for_developers: true, caller: send(:caller)) ⇒ void private
-
#ofail(error) ⇒ void
Print an error message and fail at the end of the program.
- #oh1(title, truncate: :auto) ⇒ void private
- #oh1_title(title, truncate: :auto) ⇒ String private
- #ohai(title, *sput) ⇒ void private
- #ohai_title(title) ⇒ String private
-
#onoe(message) ⇒ void
Print an error message.
-
#opoo(message) ⇒ void
Print a warning message.
-
#opoo_outside_github_actions(message) ⇒ void
Print a warning message only if not running in GitHub Actions.
- #pretty_duration(seconds) ⇒ String private
- #pretty_installed(string) ⇒ String private
- #pretty_outdated(string) ⇒ String private
- #pretty_uninstalled(string) ⇒ String private
Instance Method Details
#odebug(title, *sput, always_display: false) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'utils/output.rb', line 30 def odebug(title, *sput, always_display: false) debug = if respond_to?(:debug) T.unsafe(self).debug? else Context.current.debug? end return if !debug && !always_display $stderr.puts Formatter.headline(title.to_s, color: :magenta) $stderr.puts sput unless sput.empty? end |
#odeprecated(method, replacement = nil, disable: false, disable_on: nil, disable_for_developers: true, caller: send(:caller)) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Output a deprecation warning/error message.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'utils/output.rb', line 124 def odeprecated(method, replacement = nil, disable: false, disable_on: nil, disable_for_developers: true, caller: send(:caller)) = if replacement "Use #{replacement} instead." else "There is no replacement." end unless disable_on.nil? if disable_on > Time.now = " and will be disabled on #{disable_on.strftime("%Y-%m-%d")}" else disable = true end end verb = if disable "disabled" else "deprecated#{}" end # Try to show the most relevant location in message, i.e. (if applicable): # - Location in a formula. # - Location of caller of deprecated method (if all else fails). backtrace = caller # Don't throw deprecations at all for cached, .brew or .metadata files. return if backtrace.any? do |line| next true if line.include?(HOMEBREW_CACHE.to_s) next true if line.include?("/.brew/") next true if line.include?("/.metadata/") next false unless line.match?(HOMEBREW_TAP_PATH_REGEX) path = Pathname(line.split(":", 2).first) next false unless path.file? next false unless path.readable? formula_contents = path.read formula_contents.include?(" deprecate! ") || formula_contents.include?(" disable! ") end = T.let(nil, T.nilable(String)) backtrace.each do |line| next unless (match = line.match(HOMEBREW_TAP_PATH_REGEX)) require "tap" tap = Tap.fetch(match[:user], match[:repository]) = "\nPlease report this issue to the #{tap.full_name} tap" += " (not Homebrew/* repositories)" unless tap.official? += ", or even better, submit a PR to fix it" if replacement << ":\n #{line.sub(/^(.*:\d+):.*$/, '\1')}\n\n" break end file, line, = backtrace.first.split(":") line = line.to_i if line.present? = "Calling #{method} is #{verb}! #{}" << if .freeze disable = true if disable_for_developers && Homebrew::EnvConfig.developer? if disable || Homebrew.raise_deprecation_exceptions? require "utils/github/actions" GitHub::Actions.puts_annotation_if_env_set!(:error, , file:, line:) exception = MethodDeprecatedError.new() exception.set_backtrace(backtrace) raise exception elsif !Homebrew.auditing? opoo end end |
#odie(error) ⇒ T.noreturn
Print an error message and fail immediately.
114 115 116 117 |
# File 'utils/output.rb', line 114 def odie(error) onoe error exit 1 end |
#odisabled(method, replacement = nil, disable_on: nil, disable_for_developers: true, caller: send(:caller)) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
207 208 209 210 211 212 213 |
# File 'utils/output.rb', line 207 def odisabled(method, replacement = nil, disable_on: nil, disable_for_developers: true, caller: send(:caller)) # This odeprecated should stick around indefinitely. odeprecated(method, replacement, disable: true, disable_on:, disable_for_developers:, caller:) end |
#ofail(error) ⇒ void
This method returns an undefined value.
Print an error message and fail at the end of the program.
105 106 107 108 |
# File 'utils/output.rb', line 105 def ofail(error) onoe error Homebrew.failed = true end |
#oh1(title, truncate: :auto) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
56 57 58 |
# File 'utils/output.rb', line 56 def oh1(title, truncate: :auto) puts oh1_title(title, truncate:) end |
#oh1_title(title, truncate: :auto) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
44 45 46 47 48 49 50 51 52 53 |
# File 'utils/output.rb', line 44 def oh1_title(title, truncate: :auto) verbose = if respond_to?(:verbose?) T.unsafe(self).verbose? else Context.current.verbose? end title = Tty.truncate(title.to_s) if $stdout.tty? && !verbose && truncate == :auto Formatter.headline(title, color: :green) end |
#ohai(title, *sput) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
24 25 26 27 |
# File 'utils/output.rb', line 24 def ohai(title, *sput) puts ohai_title(title.to_s) puts sput end |
#ohai_title(title) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
12 13 14 15 16 17 18 19 20 21 |
# File 'utils/output.rb', line 12 def ohai_title(title) verbose = if respond_to?(:verbose?) T.unsafe(self).verbose? else Context.current.verbose? end title = Tty.truncate(title.to_s) if $stdout.tty? && !verbose Formatter.headline(title, color: :blue) end |
#onoe(message) ⇒ void
This method returns an undefined value.
Print an error message.
90 91 92 93 94 95 96 97 98 99 |
# File 'utils/output.rb', line 90 def onoe() require "utils/github/actions" return if GitHub::Actions.puts_annotation_if_env_set!(:error, .to_s) require "utils/formatter" Tty.with($stderr) do |stderr| stderr.puts Formatter.error(, label: "Error") end end |
#opoo(message) ⇒ void
This method returns an undefined value.
Print a warning message.
64 65 66 67 68 69 70 71 72 73 |
# File 'utils/output.rb', line 64 def opoo() require "utils/github/actions" return if GitHub::Actions.puts_annotation_if_env_set!(:warning, .to_s) require "utils/formatter" Tty.with($stderr) do |stderr| stderr.puts Formatter.warning(, label: "Warning") end end |
#opoo_outside_github_actions(message) ⇒ void
This method returns an undefined value.
Print a warning message only if not running in GitHub Actions.
79 80 81 82 83 84 |
# File 'utils/output.rb', line 79 def opoo_outside_github_actions() require "utils/github/actions" return if GitHub::Actions.env_set? opoo() end |
#pretty_duration(seconds) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'utils/output.rb', line 249 def pretty_duration(seconds) seconds = seconds.to_i res = +"" if seconds > 59 minutes = seconds / 60 seconds %= 60 res = +Utils.pluralize("minute", minutes, include_count: true) return res.freeze if seconds.zero? res << " " end res << Utils.pluralize("second", seconds, include_count: true) res.freeze end |
#pretty_installed(string) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
216 217 218 219 220 221 222 223 224 |
# File 'utils/output.rb', line 216 def pretty_installed(string) if !$stdout.tty? string elsif Homebrew::EnvConfig.no_emoji? Formatter.success("#{Tty.bold}#{string} (installed)#{Tty.reset}") else "#{Tty.bold}#{string} #{Formatter.success("✔")}#{Tty.reset}" end end |
#pretty_outdated(string) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
227 228 229 230 231 232 233 234 235 |
# File 'utils/output.rb', line 227 def pretty_outdated(string) if !$stdout.tty? string elsif Homebrew::EnvConfig.no_emoji? Formatter.error("#{Tty.bold}#{string} (outdated)#{Tty.reset}") else "#{Tty.bold}#{string} #{Formatter.warning("⚠")}#{Tty.reset}" end end |
#pretty_uninstalled(string) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
238 239 240 241 242 243 244 245 246 |
# File 'utils/output.rb', line 238 def pretty_uninstalled(string) if !$stdout.tty? string elsif Homebrew::EnvConfig.no_emoji? Formatter.error("#{Tty.bold}#{string} (uninstalled)#{Tty.reset}") else "#{Tty.bold}#{string} #{Formatter.error("✘")}#{Tty.reset}" end end |