Module: Utils::Output::Mixin Private
- Extended by:
- T::Helpers
- Included in:
- AbstractDownloadStrategy, BottleSpecification, Build, BuildError, CPAN, Cask::Artifact::AbstractArtifact, Cask::Artifact::AbstractArtifact, Cask::Audit, Cask::Auditor, Cask::CI::RunnerMatrix, Cask::Cask, Cask::CaskLoader, Cask::CaskLoader::FromNameLoader, Cask::CaskLoader::ILoader, Cask::Caskroom, Cask::Config, Cask::DSL, Cask::Info, Cask::Installer, Cask::Installer, Cask::List, Cask::Metadata, Cask::Migrator, Cask::Migrator, Cask::Pkg, Cask::Quarantine, Cask::Reinstall, Cask::Staged, Cask::Uninstall, Cask::Upgrade, Cask::Utils, Cleaner, DependentsMessage, DevelopmentTools, Downloadable, Downloadable::VerificationCache, EmbeddedPatch, ExternalPatch, Formula, Formula, FormulaInstaller, FormulaVersions, Formulary, Formulary, Formulary::FormulaLoader, Formulary::FromBottleLoader, Formulary::FromNameLoader, GitHub, GitHub::API, GitHub::API::Error, GitHub::PatchInclusion, GitHubPackages, GitHubReleases, GitHubRunnerMatrix, Homebrew, Homebrew::API, Homebrew::API::Cask::CaskStructGenerator, Homebrew::API::Cask::CaskStructGenerator, Homebrew::AbstractCommand, Homebrew::AbstractSubcommand, Homebrew::Aliases, Homebrew::Aliases::Alias, Homebrew::Ask, Homebrew::Assertions, Homebrew::Attestation, Homebrew::Bump, Homebrew::Bundle::Brew, Homebrew::Bundle::Brew::Services, Homebrew::Bundle::Cask, Homebrew::Bundle::Extension, Homebrew::Bundle::Installer, Homebrew::Bundle::Remover, Homebrew::Bundle::Skipper, Homebrew::CLI::NamedArgs, Homebrew::CLI::Parser, Homebrew::Cleanup, Homebrew::Cleanup, Homebrew::Cmd::Bundle, Homebrew::Cmd::Bundle::CleanupSubcommand, Homebrew::Cmd::Bundle::ExecSubcommand, Homebrew::Cmd::Info, Homebrew::Cmd::Services, Homebrew::Cmd::Services::ListSubcommand, Homebrew::Completions, Homebrew::Diagnostic, Homebrew::Diagnostic::Checks, Homebrew::DownloadQueue, Homebrew::EnvConfig, Homebrew::EnvConfig, Homebrew::ExecutablesDB, Homebrew::FormulaAuditor, Homebrew::FormulaCreator, Homebrew::Help, Homebrew::Install, Homebrew::InstallSteps::Runner, Homebrew::Livecheck, Homebrew::MissingFormula, Homebrew::Reinstall, Homebrew::RetryableDownload, Homebrew::Search, Homebrew::Service, Homebrew::Services::Cli, Homebrew::Services::FormulaWrapper, Homebrew::Services::System, Homebrew::Style, Homebrew::TestBot, Homebrew::TestBot::Test, Homebrew::Trust, Homebrew::Uninstall, Homebrew::UnversionedCaskChecker, Homebrew::Upgrade, Homebrew::Vulns::CachedFeed, Homebrew::Vulns::Match, Homebrew::Vulns::Scanner, Homebrew::Vulns::Vulnerability, Keg, Keg, Language::Node, Language::Python, LinkageChecker, LockFile, MacOSRequirement, Messages, Migrator, Migrator, Mktemp, OS::Linux, OS::Mac, OS::Mac::CLT, OS::Mac::Cask::Quarantine::ClassMethods, OS::Mac::Install::ClassMethods, OS::Mac::Readall::ClassMethods, OS::Mac::Reinstall::ClassMethods, Pathname, PyPI, PyPI::Package, Readall, Repology, Reporter, ReporterHub, Requirement, Resource, SBOM, Sandbox, Sandbox, Sandbox::Landlock, SharedEnvExtension, StringInreplaceExtension, Superenv, SystemCommand::Result, Tap, Tap, UnpackStrategy, UnpackStrategy, UnpackStrategy::Dmg::Bom, Analytics, Analytics::Influx, Attestation, Backtrace, Curl, Curl, Gzip, InfoDisplay, Link, Utils::Output, Path, PortableRuby, Svn, Tar
- Defined in:
- utils/output.rb
Overview
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.
Mixin used to add these helpers to stdout and stderr.
Instance Method Summary collapse
-
#issue_reporting_message(destination = nil, tier: nil, formula: nil, build_options: [], tap_action: "Report this issue") ⇒ String?
private
Without a destination, return guidance only if this configuration redirects issue reports.
- #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
Keep in sync with
ohaiin Library/Homebrew/utils.sh. -
#onoe(message) ⇒ void
Print an error message.
-
#opoo(message) ⇒ void
Print a warning message.
-
#opoo_once(message) ⇒ void
Print a warning message once per process.
-
#opoo_outside_github_actions(message) ⇒ void
Print a warning message only if not running in GitHub Actions.
- #opoo_without_github_actions_annotation(message) ⇒ void private
- #pretty_cannot_install(string, bold: true) ⇒ String private
- #pretty_deprecated(string) ⇒ String private
- #pretty_disabled(string) ⇒ String private
- #pretty_duration(seconds) ⇒ String private
- #pretty_incompatible(string) ⇒ String private
- #pretty_install_status(string, installed:, warning: false, outdated: false, deprecated: false, disabled: false, incompatible: false, removed: false, can_install: true, mark_uninstalled: false, bold: nil) ⇒ String private
-
#pretty_installed(string) ⇒ String
private
Keep status labels, colours and emoji in sync with
pretty_installedin Library/Homebrew/utils.sh. - #pretty_removed(string) ⇒ String private
-
#pretty_uninstalled(string, bold: true) ⇒ String
private
Keep status labels, colours and emoji in sync with
pretty_uninstalledin Library/Homebrew/utils.sh. - #pretty_unmarked(string, bold: true) ⇒ String private
- #pretty_upgradable(string, bold: true) ⇒ String private
- #pretty_warning(string, bold: true) ⇒ String private
Instance Method Details
#issue_reporting_message(destination = nil, tier: nil, formula: nil, build_options: [], tap_action: "Report this issue") ⇒ 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.
Without a destination, return guidance only if this configuration redirects issue reports.
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 |
# File 'utils/output.rb', line 161 def ( destination = nil, tier: nil, formula: nil, build_options: [], tap_action: "Report this issue" ) unless tier require "diagnostic" tier = Homebrew::Diagnostic.support_tier(formula:, build_options:) end provider = OS.third_party_homebrew issues_url = OS::ISSUES_URL if tier == :unsupported || provider&.tier == :unsupported || (tier == 1 && issues_url.nil?) return Formatter.bold("Do not file issues for this configuration.") end if provider = "Report problems specific to this configuration to the third-party provider." url = provider.issues_url return url ? "#{}\n #{Formatter.url(url)}" : end if destination.is_a?(Tap) && (tier == 1 || !destination.official?) = "#{tap_action} to the #{destination.full_name} tap" url = destination.issues_url return url ? "#{}:\n #{Formatter.url(url)}" : "#{}." end if [2, 3].include?(tier) return <<~EOS.chomp Please do not file Homebrew issues for problems specific to Tier #{tier}. Ask the community on Homebrew Discussions: #{Formatter.url("https://github.com/orgs/Homebrew/discussions")} EOS end case destination when :homebrew then "Before reporting this issue, read:\n #{Formatter.url(issues_url)}" if issues_url when String then "If reporting this issue, use:\n #{Formatter.url(destination)}" end end |
#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.
65 66 67 68 69 70 |
# File 'utils/output.rb', line 65 def odebug(title, *sput, always_display: false) return if !always_display && !output_context?(:debug?) $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.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'utils/output.rb', line 215 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]) = "\n#{(tap)}\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? exception = MethodDeprecatedError.new() exception.set_backtrace(backtrace) begin raise exception rescue MethodDeprecatedError require "utils/github/actions" GitHub::Actions.puts_annotation_if_env_set!(:error, , file:, line:) # Do not offer an already-rejected exception to Ignorable again. Kernel.raise end elsif !Homebrew.auditing? opoo_once end end |
#odie(error) ⇒ T.noreturn
Print an error message and fail immediately.
Keep in sync with odie in Library/Homebrew/utils.sh.
205 206 207 208 |
# File 'utils/output.rb', line 205 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.
300 301 302 303 304 305 306 |
# File 'utils/output.rb', line 300 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.
150 151 152 153 |
# File 'utils/output.rb', line 150 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.
79 80 81 |
# File 'utils/output.rb', line 79 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.
73 74 75 76 |
# File 'utils/output.rb', line 73 def oh1_title(title, truncate: :auto) title = Tty.truncate(title.to_s) if $stdout.tty? && truncate == :auto && !output_context?(:verbose?) 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.
59 60 61 62 |
# File 'utils/output.rb', line 59 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.
Keep in sync with ohai in Library/Homebrew/utils.sh.
53 54 55 56 |
# File 'utils/output.rb', line 53 def ohai_title(title) title = Tty.truncate(title.to_s) if $stdout.tty? && !output_context?(:verbose?) Formatter.headline(title, color: :blue) end |
#onoe(message) ⇒ void
This method returns an undefined value.
Print an error message.
Keep in sync with onoe in Library/Homebrew/utils.sh.
135 136 137 138 139 140 141 142 143 144 |
# File 'utils/output.rb', line 135 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.
Keep in sync with opoo in Library/Homebrew/utils.sh.
88 89 90 91 92 93 94 95 96 97 |
# File 'utils/output.rb', line 88 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_once(message) ⇒ void
This method returns an undefined value.
Print a warning message once per process.
103 104 105 |
# File 'utils/output.rb', line 103 def opoo_once() opoo if Utils::Output.claim_warning(.to_s) end |
#opoo_outside_github_actions(message) ⇒ void
This method returns an undefined value.
Print a warning message only if not running in GitHub Actions.
123 124 125 126 127 128 |
# File 'utils/output.rb', line 123 def opoo_outside_github_actions() require "utils/github/actions" return if GitHub::Actions.env_set? opoo() end |
#opoo_without_github_actions_annotation(message) ⇒ 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.
108 109 110 111 112 113 114 115 116 117 |
# File 'utils/output.rb', line 108 def opoo_without_github_actions_annotation() require "utils/github/actions" return opoo() unless GitHub::Actions.env_set? require "utils/formatter" Tty.with($stderr) do |stderr| stderr.puts Formatter.warning(, label: "Warning") end end |
#pretty_cannot_install(string, bold: true) ⇒ 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.
370 371 372 373 374 375 376 377 378 379 |
# File 'utils/output.rb', line 370 def pretty_cannot_install(string, bold: true) weight = bold ? Tty.bold.to_s : "" if !$stdout.tty? string elsif Homebrew::EnvConfig.no_emoji? Formatter.error("#{weight}#{string} (can't be installed)#{Tty.reset}") else "#{weight}#{string} #{Formatter.error("⊘")}#{Tty.reset}" end end |
#pretty_deprecated(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.
334 335 336 337 338 339 340 |
# File 'utils/output.rb', line 334 def pretty_deprecated(string) if $stdout.tty? "#{string} #{Formatter.warning("(deprecated)")}" else string end end |
#pretty_disabled(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.
343 344 345 346 347 348 349 |
# File 'utils/output.rb', line 343 def pretty_disabled(string) if $stdout.tty? "#{string} #{Formatter.error("(disabled)")}" else string end 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.
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'utils/output.rb', line 452 def pretty_duration(seconds) seconds = seconds.to_i hide_seconds = seconds > 300 minutes, seconds = seconds.divmod(60) hours, minutes = minutes.divmod(60) res = +"" if hours.positive? res << Utils.pluralize("hour", hours, include_count: true) return res.freeze if minutes.zero? res << " " << Utils.pluralize("minute", minutes, include_count: true) return res.freeze end if minutes.positive? res << Utils.pluralize("minute", minutes, include_count: true) return res.freeze if hide_seconds || seconds.zero? res << " " end res << Utils.pluralize("second", seconds, include_count: true) res.freeze end |
#pretty_incompatible(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.
352 353 354 355 356 357 358 |
# File 'utils/output.rb', line 352 def pretty_incompatible(string) if $stdout.tty? "#{string} #{Formatter.error("(incompatible)")}" else string end end |
#pretty_install_status(string, installed:, warning: false, outdated: false, deprecated: false, disabled: false, incompatible: false, removed: false, can_install: true, mark_uninstalled: false, bold: nil) ⇒ 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.
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'utils/output.rb', line 421 def pretty_install_status(string, installed:, warning: false, outdated: false, deprecated: false, disabled: false, incompatible: false, removed: false, can_install: true, mark_uninstalled: false, bold: nil) bold = installed if bold.nil? status = if warning pretty_warning(string, bold:) elsif installed && outdated pretty_upgradable(string, bold:) elsif installed pretty_installed(string) elsif !can_install pretty_cannot_install(string, bold:) elsif mark_uninstalled pretty_uninstalled(string, bold:) else pretty_unmarked(string, bold:) end if removed pretty_removed(status) elsif disabled pretty_disabled(status) elsif incompatible pretty_incompatible(status) elsif deprecated pretty_deprecated(status) else status end 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.
Keep status labels, colours and emoji in sync with
pretty_installed in Library/Homebrew/utils.sh.
311 312 313 314 315 316 317 318 319 |
# File 'utils/output.rb', line 311 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_removed(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.
361 362 363 364 365 366 367 |
# File 'utils/output.rb', line 361 def pretty_removed(string) if $stdout.tty? "#{string} #{Formatter.warning("(removed from tap)")}" else string end end |
#pretty_uninstalled(string, bold: true) ⇒ 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.
Keep status labels, colours and emoji in sync with
pretty_uninstalled in Library/Homebrew/utils.sh.
384 385 386 387 388 389 390 391 392 393 |
# File 'utils/output.rb', line 384 def pretty_uninstalled(string, bold: true) weight = bold ? Tty.bold.to_s : "" if !$stdout.tty? string elsif Homebrew::EnvConfig.no_emoji? Formatter.error("#{weight}#{string} (uninstalled)#{Tty.reset}") else "#{weight}#{string} #{Formatter.error("✘")}#{Tty.reset}" end end |
#pretty_unmarked(string, bold: true) ⇒ 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.
396 397 398 399 400 401 402 |
# File 'utils/output.rb', line 396 def pretty_unmarked(string, bold: true) if bold && $stdout.tty? "#{Tty.bold}#{string}#{Tty.reset}" else string end end |
#pretty_upgradable(string, bold: true) ⇒ 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.
322 323 324 325 326 327 328 329 330 331 |
# File 'utils/output.rb', line 322 def pretty_upgradable(string, bold: true) weight = bold ? Tty.bold.to_s : "" if !$stdout.tty? string elsif Homebrew::EnvConfig.no_emoji? "#{weight}#{string} (upgradable)#{Tty.reset}" else "#{weight}#{string} #{Formatter.success("↑")}#{Tty.reset}" end end |
#pretty_warning(string, bold: true) ⇒ 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.
405 406 407 408 409 410 411 412 413 414 |
# File 'utils/output.rb', line 405 def pretty_warning(string, bold: true) weight = bold ? Tty.bold.to_s : "" if !$stdout.tty? string elsif Homebrew::EnvConfig.no_emoji? Formatter.warning("#{weight}#{string} (warning)#{Tty.reset}") else "#{weight}#{string} #{Formatter.warning("⚠")}#{Tty.reset}" end end |