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::Cask, Cask::CaskLoader, Cask::CaskLoader::FromNameLoader, 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, DependentsMessage, Downloadable, EmbeddedPatch, ExternalPatch, Formula, Formula, FormulaInstaller, FormulaVersions, Formulary, Formulary, Formulary::FormulaLoader, Formulary::FromBottleLoader, Formulary::FromNameLoader, GitHub, GitHub::API, GitHub::API::Error, GitHubPackages, GitHubReleases, Homebrew, Homebrew::API, 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::Installer, Homebrew::Bundle::Remover, Homebrew::CLI::NamedArgs, Homebrew::CLI::Parser, Homebrew::Cleanup, Homebrew::Cleanup, Homebrew::Cmd::Bundle, Homebrew::Cmd::Bundle::ExecSubcommand, 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::Livecheck, Homebrew::MissingFormula, Homebrew::Reinstall, Homebrew::RetryableDownload, Homebrew::Search, Homebrew::Services::Cli, Homebrew::Services::FormulaWrapper, Homebrew::Services::System, Homebrew::Style, Homebrew::TestBot, Homebrew::TestBot::Test, Homebrew::Trust, Homebrew::Uninstall, Homebrew::UnversionedCaskChecker, Homebrew::Upgrade, Keg, Keg, Language::Node, Language::Python, LinkageChecker, LockFile, Messages, Migrator, Migrator, Mktemp, OS::Linux, OS::Linux::Sandbox::ClassMethods, OS::Mac, OS::Mac::CLT, OS::Mac::Readall::ClassMethods, OS::Mac::Reinstall::ClassMethods, Pathname, PyPI, PyPI::Package, Readall, Repology, Reporter, ReporterHub, Requirement, Resource, SBOM, Sandbox, SharedEnvExtension, StringInreplaceExtension, Superenv, SystemCommand::Result, Tap, Tap, UnpackStrategy, UnpackStrategy, UnpackStrategy::Dmg::Bom, Analytics, Attestation, Backtrace, Curl, Curl, Gzip, Link, Utils::Output, 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

Instance Method Details

#issue_reporting_message(issues_url, homebrew: false, read_this: false) ⇒ 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.

Parameters:

  • issues_url (String)
  • homebrew (Boolean) (defaults to: false)
  • read_this (Boolean) (defaults to: false)

Returns:



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'utils/output.rb', line 128

def issue_reporting_message(issues_url, homebrew: false, read_this: false)
  formatted_issues_url = Formatter.url(issues_url)

  if read_this
    Formatter.error(formatted_issues_url, label: "READ THIS")
  elsif homebrew
    <<~EOS
      #{Tty.bold}Please report this issue:#{Tty.reset}
        #{formatted_issues_url}
    EOS
  else
    <<~EOS
      If reporting this issue please do so at (not Homebrew/* repositories):
        #{formatted_issues_url}
    EOS
  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.

Parameters:

  • title (String, Exception)
  • sput (T.anything)
  • always_display (Boolean) (defaults to: false)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'utils/output.rb', line 33

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.

Parameters:

  • method (String)
  • replacement (String, Symbol, nil) (defaults to: nil)
  • disable (Boolean) (defaults to: false)
  • disable_on (Time, nil) (defaults to: nil)
  • disable_for_developers (Boolean) (defaults to: true)
  • caller (Array<String>) (defaults to: send(:caller))


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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'utils/output.rb', line 161

def odeprecated(method, replacement = nil,
                disable:                false,
                disable_on:             nil,
                disable_for_developers: true,
                caller:                 send(:caller))
  replacement_message = if replacement
    "Use #{replacement} instead."
  else
    "There is no replacement."
  end

  unless disable_on.nil?
    if disable_on > Time.now
      will_be_disabled_message = " and will be disabled on #{disable_on.strftime("%Y-%m-%d")}"
    else
      disable = true
    end
  end

  verb = if disable
    "disabled"
  else
    "deprecated#{will_be_disabled_message}"
  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

  tap_message = 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])
    tap_message = "\nPlease report this issue to the #{tap.full_name} tap"
    tap_message += " (not Homebrew/* repositories)" unless tap.official?
    tap_message += ", or even better, submit a PR to fix it" if replacement
    tap_message << ":\n  #{line.sub(/^(.*:\d+):.*$/, '\1')}\n\n"
    break
  end
  file, line, = backtrace.first.split(":")
  line = line.to_i if line.present?

  message = "Calling #{method} is #{verb}! #{replacement_message}"
  message << tap_message if tap_message
  message.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, message, file:, line:)
    exception = MethodDeprecatedError.new(message)
    exception.set_backtrace(backtrace)
    raise exception
  elsif !Homebrew.auditing?
    opoo message
  end
end

#odie(error) ⇒ T.noreturn

Print an error message and fail immediately.

Keep in sync with odie in Library/Homebrew/utils.sh.

Parameters:

Returns:

  • (T.noreturn)


151
152
153
154
# File 'utils/output.rb', line 151

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.

Parameters:

  • method (String)
  • replacement (String, Symbol, nil) (defaults to: nil)
  • disable_on (Time, nil) (defaults to: nil)
  • disable_for_developers (Boolean) (defaults to: true)
  • caller (Array<String>) (defaults to: send(:caller))


244
245
246
247
248
249
250
# File 'utils/output.rb', line 244

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.

Parameters:



122
123
124
125
# File 'utils/output.rb', line 122

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.

Parameters:

  • title (String)
  • truncate (Symbol, Boolean) (defaults to: :auto)


59
60
61
# File 'utils/output.rb', line 59

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.

Parameters:

  • title (String)
  • truncate (Symbol, Boolean) (defaults to: :auto)

Returns:



47
48
49
50
51
52
53
54
55
56
# File 'utils/output.rb', line 47

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.

Parameters:

  • title (String, Exception)
  • sput (T.anything)


27
28
29
30
# File 'utils/output.rb', line 27

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.

Parameters:

Returns:



15
16
17
18
19
20
21
22
23
24
# File 'utils/output.rb', line 15

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.

Keep in sync with onoe in Library/Homebrew/utils.sh.

Parameters:



107
108
109
110
111
112
113
114
115
116
# File 'utils/output.rb', line 107

def onoe(message)
  require "utils/github/actions"
  return if GitHub::Actions.puts_annotation_if_env_set!(:error, message.to_s)

  require "utils/formatter"

  Tty.with($stderr) do |stderr|
    stderr.puts Formatter.error(message, 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.

Parameters:



68
69
70
71
72
73
74
75
76
77
# File 'utils/output.rb', line 68

def opoo(message)
  require "utils/github/actions"
  return if GitHub::Actions.puts_annotation_if_env_set!(:warning, message.to_s)

  require "utils/formatter"

  Tty.with($stderr) do |stderr|
    stderr.puts Formatter.warning(message, 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.

Parameters:



95
96
97
98
99
100
# File 'utils/output.rb', line 95

def opoo_outside_github_actions(message)
  require "utils/github/actions"
  return if GitHub::Actions.env_set?

  opoo(message)
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.

Parameters:



80
81
82
83
84
85
86
87
88
89
# File 'utils/output.rb', line 80

def opoo_without_github_actions_annotation(message)
  require "utils/github/actions"
  return opoo(message) unless GitHub::Actions.env_set?

  require "utils/formatter"

  Tty.with($stderr) do |stderr|
    stderr.puts Formatter.warning(message, label: "Warning")
  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.

Parameters:

Returns:



288
289
290
291
292
293
294
# File 'utils/output.rb', line 288

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.

Parameters:

Returns:



297
298
299
300
301
302
303
# File 'utils/output.rb', line 297

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.

Parameters:

Returns:



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'utils/output.rb', line 343

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_install_status(string, installed:, outdated: false, deprecated: false, disabled: false, mark_uninstalled: 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.

Parameters:

  • string (String)
  • installed (Boolean)
  • outdated (Boolean) (defaults to: false)
  • deprecated (Boolean) (defaults to: false)
  • disabled (Boolean) (defaults to: false)
  • mark_uninstalled (Boolean) (defaults to: true)

Returns:



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'utils/output.rb', line 322

def pretty_install_status(string, installed:, outdated: false, deprecated: false, disabled: false,
                          mark_uninstalled: true)
  status = if installed && outdated
    pretty_upgradable(string)
  elsif installed
    pretty_installed(string)
  elsif mark_uninstalled
    pretty_uninstalled(string)
  else
    string
  end
  if disabled
    pretty_disabled(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.

Parameters:

Returns:



255
256
257
258
259
260
261
262
263
# File 'utils/output.rb', line 255

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.

Parameters:

Returns:



266
267
268
269
270
271
272
273
274
# File 'utils/output.rb', line 266

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.

Keep status labels, colours and emoji in sync with pretty_uninstalled in Library/Homebrew/utils.sh.

Parameters:

Returns:



308
309
310
311
312
313
314
315
316
# File 'utils/output.rb', line 308

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

#pretty_upgradable(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.

Parameters:

Returns:



277
278
279
280
281
282
283
284
285
# File 'utils/output.rb', line 277

def pretty_upgradable(string)
  if !$stdout.tty?
    string
  elsif Homebrew::EnvConfig.no_emoji?
    "#{Tty.bold}#{string} (upgradable)#{Tty.reset}"
  else
    "#{Tty.bold}#{string} #{Formatter.success("")}#{Tty.reset}"
  end
end