Class: Cask::Info

Inherits:
Object show all
Extended by:
Utils::Output::Mixin
Defined in:
cask/info.rb

Class Method Summary collapse

Methods included from Utils::Output::Mixin

issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_once, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_cannot_install, pretty_deprecated, pretty_disabled, pretty_duration, pretty_incompatible, pretty_install_status, pretty_installed, pretty_removed, pretty_uninstalled, pretty_unmarked, pretty_upgradable, pretty_warning

Class Method Details

.artifact_info(cask) ⇒ 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:



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
# File 'cask/info.rb', line 199

def self.artifact_info(cask)
  groups = T.let({}, T::Hash[String, T::Array[String]])
  cask.artifacts.each do |artifact|
    next unless artifact.respond_to?(:install_phase)
    next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class)
    next if artifact.is_a?(Artifact::Binary)

    heading, detail = case artifact
    when Artifact::App, Artifact::AppImage
      ["Apps", artifact.summarize]
    when Artifact::Font
      ["Fonts", artifact.summarize]
    when Artifact::Manpage
      ["Manpages", artifact.summarize]
    when Artifact::AudioUnitPlugin, Artifact::Colorpicker, Artifact::InternetPlugin, Artifact::Qlplugin,
         Artifact::VstPlugin, Artifact::Vst3Plugin
      ["Plugins", artifact.to_s]
    else
      ["Artifacts", artifact.to_s]
    end
    (groups[heading] ||= []) << detail
  end
  return if groups.empty?

  %w[Apps Fonts Manpages Plugins Artifacts].filter_map do |heading|
    next unless (artifacts = groups[heading])

    [ohai_title(heading), *artifacts].join("\n")
  end.join("\n")
end

.decorate_dependency(dep, installed:, 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:

  • dep (String)
  • installed (Boolean)
  • mark_uninstalled (Boolean) (defaults to: true)

Returns:



173
174
175
# File 'cask/info.rb', line 173

def self.decorate_dependency(dep, installed:, mark_uninstalled: true)
  pretty_install_status(dep, installed:, mark_uninstalled:)
end

.deps_info(cask, 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:

  • cask (Cask)
  • mark_uninstalled (Boolean) (defaults to: true)

Returns:



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
# File 'cask/info.rb', line 130

def self.deps_info(cask, mark_uninstalled: true)
  depends_on = cask.depends_on

  formula_deps = Array(depends_on[:formula]).map do |dep|
    name = dep.to_s
    decorate_dependency(
      name,
      installed:        Formula.rack_installed?(name),
      mark_uninstalled:,
    )
  end

  cask_deps = Array(depends_on[:cask]).map do |dep|
    name = dep.to_s
    decorate_dependency(
      "#{name} (cask)",
      installed:        (Caskroom.path/name).directory?,
      mark_uninstalled:,
    )
  end

  all_deps = formula_deps + cask_deps
  return if all_deps.empty?

  formula_dependencies = T.let(Set.new, T::Set[String])
  cask_dependencies = T.let(Set.new, T::Set[String])
  ::Utils::InfoDisplay.collect_cask_dependency_names(cask, formula_dependencies, cask_dependencies,
                                                     Set[cask.token])
  recursive_count = formula_dependencies.count + cask_dependencies.count
  lines = ["Required (#{all_deps.count}): #{all_deps.join(", ")}"]
  unless recursive_count.zero?
    installed_count = formula_dependencies.count do |name|
      Formula.rack_installed?(name)
    end + cask_dependencies.count do |name|
      (Caskroom.path/name).directory?
    end
    lines << ::Utils::InfoDisplay.recursive_runtime_line(installed_count, recursive_count)
  end

  "#{::Utils::InfoDisplay.section("Dependencies", lines)}\n"
end

.get_info(cask, verbose: 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:

  • cask (Cask)
  • verbose (Boolean) (defaults to: false)

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'cask/info.rb', line 15

def self.get_info(cask, verbose: false)
  require "cask/installer"

  installed = cask.installed?
  outdated = installed && cask.outdated?
  summary = ::Utils::InfoDisplay.package_summary(
    formula_or_cask:     cask,
    title:               ::Utils::InfoDisplay::Title.new(
      name:              cask.token,
      display_names:     cask.name,
      version:           cask.version.to_s,
      installed_version: (cask.installed_version.presence if outdated),
      installed:,
      outdated:,
      auto_updates:      cask.auto_updates == true,
    ),
    installation_status: [installation_info(cask, installed:)],
    source_url:          repo_url(cask),
    installed_versions:  installed_section_rows(cask),
    verbose:,
  )
  output = "#{summary}\n"
  deps = deps_info(cask, mark_uninstalled: installed)
  output << deps if deps
  require "cask_dependent"
  requirements = CaskDependent.new(cask).requirements.grep_v(CaskDependent::Requirement)
  if requirements.present?
    requirements_section = ::Utils::InfoDisplay.requirements_section(
      requirements, omit_macos_linux: !cask.supports_linux?
    )
    output << "#{requirements_section}\n" if requirements_section
  end
  language = language_info(cask)
  output << language if language
  artifacts = artifact_info(cask)
  output << "#{artifacts}\n" if artifacts
  if verbose
    binaries = cask.artifacts.grep(Artifact::Binary).map { |binary| binary.target.basename.to_s }
    if binaries.present?
      binaries_section = ::Utils::InfoDisplay.binaries_section(binaries).chomp
      output << "#{binaries_section}\n"
    end
  end
  caveats = Installer.caveats(cask)
  output << caveats if caveats
  output
end

.info(cask, args:) ⇒ 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:



64
65
66
67
68
69
70
71
# File 'cask/info.rb', line 64

def self.info(cask, args:)
  puts get_info(cask, verbose: args.verbose?)

  return unless cask.tap&.core_cask_tap?

  require "utils/analytics"
  ::Utils::Analytics.cask_output(cask, args:)
end

.installation_info(cask, installed:) ⇒ 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:

  • cask (Cask)
  • installed (Boolean)

Returns:



74
75
76
77
78
79
# File 'cask/info.rb', line 74

def self.installation_info(cask, installed:)
  return "Not installed" unless installed
  return "No installed version" unless cask.installed_version.present?

  ::Utils::InfoDisplay.installation_status(Tab.for_cask(cask))
end

.installed_section_rows(cask) ⇒ Array<::Utils::InfoDisplay::InstalledVersion>

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:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'cask/info.rb', line 82

def self.installed_section_rows(cask)
  base_token = cask.token.split("@", 2).fetch(0)
  matching_token = ->(token) { token == base_token || token.start_with?("#{base_token}@") }
  tokens = Caskroom.tokens
  renamed_tokens = (tokens.empty? ? [] : Tap.to_a).flat_map do |tap|
    (tap.cask_renames.keys | tap.tap_migrations.keys).intersection(tokens).select do |token|
      resolved = CaskLoader.tap_cask_token_type("#{tap}/#{token}", warn: false)
      resolved && matching_token.call(resolved.first)
    end
  end
  related_tokens = tokens.select { |token| matching_token.call(token) || renamed_tokens.include?(token) }
  related_casks = [*Caskroom.casks(tokens: related_tokens), cask].uniq(&:token).select do |other|
    other.token == base_token || other.token.start_with?("#{base_token}@")
  end
  related_casks.sort_by(&:full_name).filter_map do |installed_cask|
    installed_version = installed_cask.installed_version
    next unless installed_version.present?

    versioned_staged_path = installed_cask.caskroom_path.join(installed_version)
    path_exists = versioned_staged_path.exist?
    size = if path_exists
      path_details = versioned_staged_path.children.sum(&:disk_usage)
      "(#{Formatter.disk_usage_readable(path_details)})"
    else
      ""
    end
    details = path_exists ? ["Caskroom: #{versioned_staged_path}"] : []
    if (tab = Tab.for_cask(installed_cask)).tabfile&.exist?
      details << tab.to_s
    end

    outdated = installed_cask.outdated?
    name = pretty_install_status(installed_cask.full_name, installed: true, outdated:)
    version = installed_version
    latest = installed_cask.version.to_s
    version = "#{version} → #{latest}" if outdated && latest != version
    ::Utils::InfoDisplay::InstalledVersion.new(
      name:,
      version:,
      size:,
      linked: false,
      details:,
      warning: ("#{versioned_staged_path} (#{Formatter.error("does not exist")})" unless path_exists),
    )
  end
end

.language_info(cask) ⇒ 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:



178
179
180
181
182
183
184
185
# File 'cask/info.rb', line 178

def self.language_info(cask)
  return if cask.languages.empty?

  <<~EOS
    #{ohai_title("Languages")}
    #{cask.languages.join(", ")}
  EOS
end

.repo_url(cask) ⇒ 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:



188
189
190
191
192
193
194
195
196
# File 'cask/info.rb', line 188

def self.repo_url(cask)
  return unless (tap = cask.tap)

  if tap.custom_remote? && !tap.remote.nil?
    tap.remote
  else
    "#{tap.default_remote}/blob/HEAD/#{tap.relative_cask_path(cask.token)}"
  end
end