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

odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_deprecated, pretty_disabled, pretty_duration, pretty_installed, pretty_outdated, pretty_uninstalled

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:



192
193
194
195
196
197
198
199
200
201
# File 'cask/info.rb', line 192

def self.artifact_info(cask)
  artifact_output = ohai_title("Artifacts").dup
  cask.artifacts.each do |artifact|
    next unless artifact.respond_to?(:install_phase)
    next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class)

    artifact_output << "\n" << artifact.to_s
  end
  artifact_output.freeze
end

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

  • dep (String)
  • installed (Boolean)

Returns:



127
128
129
# File 'cask/info.rb', line 127

def self.decorate_dependency(dep, installed:)
  installed ? pretty_installed(dep) : pretty_uninstalled(dep)
end

.deps_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:



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

def self.deps_info(cask)
  depends_on = cask.depends_on

  formula_deps = Array(depends_on[:formula]).map do |dep|
    name = dep.to_s
    rack = HOMEBREW_CELLAR/name.split("/").last
    decorate_dependency(name, installed: rack.directory? && !rack.subdirs.empty?)
  end

  cask_deps = Array(depends_on[:cask]).map do |dep|
    name = dep.to_s
    decorate_dependency("#{name} (cask)", installed: (Caskroom.path/name).directory?)
  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])
  Homebrew::Cmd::Info.collect_cask_dependency_names(cask, formula_dependencies, cask_dependencies,
                                                    Set[cask.token])
  recursive_count = formula_dependencies.count + cask_dependencies.count
  lines = T.let(
    [ohai_title("Dependencies").to_s, "Required (#{all_deps.count}): #{all_deps.join(", ")}"],
    T::Array[String],
  )
  unless recursive_count.zero?
    installed_count = formula_dependencies.count do |name|
      rack = HOMEBREW_CELLAR/name.split("/").last
      rack.directory? && !rack.subdirs.empty?
    end + cask_dependencies.count do |name|
      (Caskroom.path/name).directory?
    end
    lines << "Recursive Runtime (#{recursive_count}): " \
             "#{Homebrew::Cmd::Info.dependency_status_counts(installed_count, recursive_count)}"
  end

  "#{lines.join("\n")}\n"
end

.get_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:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'cask/info.rb', line 13

def self.get_info(cask)
  require "cask/installer"

  installed = cask.installed?
  output = "#{title_info(cask, installed:)}\n"
  output << "#{cask.desc}\n" if cask.desc
  output << "#{Formatter.url(cask.homepage)}\n" if cask.homepage
  deprecate_disable = DeprecateDisable.message(cask)
  if deprecate_disable.present?
    deprecate_disable.tap { |message| message[0] = message[0].upcase }
    output << "#{deprecate_disable}\n"
  end
  output << "#{installation_info(cask, installed:)}\n"
  repo = repo_info(cask)
  output << "#{repo}\n" if repo
  deps = deps_info(cask)
  output << deps if deps
  requirements = requirements_info(cask)
  output << requirements if requirements
  language = language_info(cask)
  output << language if language
  output << "#{artifact_info(cask)}\n"
  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:



41
42
43
44
45
46
47
48
# File 'cask/info.rb', line 41

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

  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:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'cask/info.rb', line 65

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

  versioned_staged_path = cask.caskroom_path.join(installed_version)
  tab = Tab.for_cask(cask)

  unless versioned_staged_path.exist?
    return "#{Homebrew::Cmd::Info.installation_status(tab)}\n" \
           "#{versioned_staged_path} (#{Formatter.error("does not exist")})\n"
  end

  path_details = versioned_staged_path.children.sum(&:disk_usage)

  info = [Homebrew::Cmd::Info.installation_status(tab)]
  info << "#{versioned_staged_path} (#{Formatter.disk_usage_readable(path_details)})"
  info << "  #{tab}" if tab.tabfile&.exist?
  info.join("\n")
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:



169
170
171
172
173
174
175
176
# File 'cask/info.rb', line 169

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

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

.repo_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:



179
180
181
182
183
184
185
186
187
188
189
# File 'cask/info.rb', line 179

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

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

  "From: #{Formatter.url(url)}"
end

.requirements_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:



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

def self.requirements_info(cask)
  require "cask_dependent"

  requirements = CaskDependent.new(cask).requirements.grep_v(CaskDependent::Requirement)
  return if requirements.empty?

  supports_linux = cask.supports_linux?
  output = "#{ohai_title("Requirements")}\n"
  %w[build required recommended optional].each do |type|
    reqs = case type
    when "build"
      requirements.select(&:build?)
    when "required"
      requirements.select(&:required?)
    when "recommended"
      requirements.select(&:recommended?)
    when "optional"
      requirements.select(&:optional?)
    else
      []
    end
    next if reqs.empty?

    output << "#{type.capitalize}: #{reqs.map do |requirement|
      requirement_s = if requirement.is_a?(MacOSRequirement) && !supports_linux
        requirement.display_s.delete_suffix(" (or Linux)")
      else
        requirement.display_s
      end
      installed = requirement.satisfied?
      installed ? pretty_installed(requirement_s) : pretty_uninstalled(requirement_s)
    end.join(", ")}\n"
  end
  output
end

.title_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:



51
52
53
54
55
56
57
58
59
60
61
62
# File 'cask/info.rb', line 51

def self.title_info(cask, installed:)
  name_with_status = if installed
    pretty_installed(cask.token)
  else
    pretty_uninstalled(cask.token)
  end
  title = oh1_title(name_with_status).to_s
  title += " (#{cask.name.join(", ")})" unless cask.name.empty?
  title += ": #{cask.version}"
  title += " (auto_updates)" if cask.auto_updates
  title
end