Class: Homebrew::Cmd::Info Private

Inherits:
AbstractCommand show all
Defined in:
cmd/info.rb,
sorbet/rbi/dsl/homebrew/cmd/info.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Constant Summary collapse

VALID_DAYS =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

%w[30 90 365].freeze
VALID_FORMULA_CATEGORIES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

%w[install install-on-request build-error].freeze
VALID_CATEGORIES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let((VALID_FORMULA_CATEGORIES + %w[cask-install os-version]).freeze, T::Array[String])

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

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

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Class Method Details

.collect_cask_dependency_names(cask, formula_dependencies, cask_dependencies, visited_casks) ⇒ 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:

  • cask (T.untyped)
  • formula_dependencies (Set<String>)
  • cask_dependencies (Set<String>)
  • visited_casks (Set<String>)


303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'cmd/info.rb', line 303

def self.collect_cask_dependency_names(cask, formula_dependencies, cask_dependencies, visited_casks)
  cask.depends_on.formula.each do |name|
    dep_name = name.to_s
    formula_dependencies << dep_name
    rack = HOMEBREW_CELLAR/Utils.name_from_full_name(dep_name)
    next unless rack.directory?

    keg = Keg.from_rack(rack)
    next unless keg

    tab_deps = Tab.for_keg(keg).runtime_dependencies
    tab_deps&.each do |runtime_dep|
      dep_full_name = T.cast(runtime_dep, T::Hash[String, T.untyped])["full_name"]
      formula_dependencies << dep_full_name if dep_full_name
    end
  end

  cask.depends_on.cask.each do |name|
    token = name.to_s
    next if visited_casks.include?(token)

    cask_dependencies << token
    visited_casks << token
    begin
      dependency = Cask::CaskLoader.load(token)
      collect_cask_dependency_names(dependency, formula_dependencies, cask_dependencies, visited_casks)
    rescue Cask::CaskUnavailableError
      next
    end
  end
end

.dependency_status_counts(installed_count, total_count) ⇒ 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:



203
204
205
206
207
208
209
# File 'cmd/info.rb', line 203

def self.dependency_status_counts(installed_count, total_count)
  missing_count = total_count - installed_count
  return "all installed #{Formatter.success("")}" if missing_count.zero?

  "#{installed_count} installed #{Formatter.success("")}, " \
    "#{missing_count} missing #{Formatter.error("")}"
end

.installation_reason(tab) ⇒ 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:



184
185
186
187
188
# File 'cmd/info.rb', line 184

def self.installation_reason(tab)
  return "-" unless tab.installed_on_request_present?

  tab.installed_on_request ? "on request" : "dependency"
end

.installation_status(tab) ⇒ 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:



177
178
179
180
181
# File 'cmd/info.rb', line 177

def self.installation_status(tab)
  # TODO: Deprecate reading `installed_as_dependency`; `installed_on_request`
  # is the only state we need to render install intent.
  tab.installed_on_request ? "Installed (on request)" : "Installed (as dependency)"
end

.installation_summary(version, tab) ⇒ 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:



191
192
193
194
195
# File 'cmd/info.rb', line 191

def self.installation_summary(version, tab)
  reason = installation_reason(tab)

  "Installed: #{version}#{" (#{reason})" if reason != "-"}"
end

.installed_dependent_names(full_name, name) ⇒ Array<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:



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'cmd/info.rb', line 212

def self.installed_dependent_names(full_name, name)
  Formula.racks.filter_map do |rack|
    keg = Keg.from_rack(rack)
    next unless keg

    tab_path = keg/AbstractTab::FILENAME
    next unless tab_path.file?

    # Fast path: skip JSON parsing when the formula name
    # does not appear anywhere in the raw receipt.
    content = File.read(tab_path)
    next unless content.include?(name)

    tab_deps = Tab.from_file_content(content, tab_path).runtime_dependencies
    next unless tab_deps

    dependent = tab_deps.any? do |dep|
      dep_full_name = T.cast(dep, T::Hash[String, T.untyped])["full_name"]
      dep_full_name == full_name || dep_full_name&.then { Utils.name_from_full_name(it) } == name
    end
    keg.name if dependent
  end.sort.uniq
end

.metadata_lines(formula_or_cask) ⇒ Array<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:

  • formula_or_cask (T.untyped)

Returns:



152
153
154
155
156
157
158
159
160
161
162
# File 'cmd/info.rb', line 152

def self.(formula_or_cask)
  return [] unless $stdout.tty?

  if formula_or_cask.is_a?(Formula) || formula_or_cask.respond_to?(:pinned?)
    (formula_or_cask)
  elsif formula_or_cask.is_a?(Cask::Cask) || formula_or_cask.respond_to?(:supports_macos?)
    []
  else
    raise TypeError, "Unsupported formula_or_cask type: #{formula_or_cask.class}"
  end
end

.requirement_for_other_os?(requirement) ⇒ Boolean

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:

  • (Boolean)


198
199
200
# File 'cmd/info.rb', line 198

def self.requirement_for_other_os?(requirement)
  requirement.instance_of?(MacOSRequirement) || requirement.instance_of?(LinuxRequirement)
end

.requirements_lines(formula_or_cask) ⇒ Array<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:

  • formula_or_cask (T.untyped)

Returns:

Raises:

  • (TypeError)


165
166
167
168
169
170
171
172
173
174
# File 'cmd/info.rb', line 165

def self.requirements_lines(formula_or_cask)
  return [] unless $stdout.tty?
  return [] if formula_or_cask.is_a?(Formula) || formula_or_cask.respond_to?(:pinned?)
  if formula_or_cask.is_a?(Cask::Cask) || formula_or_cask.respond_to?(:supports_macos?)
    return cask_requirements_lines(formula_or_cask)
  end

  raise TypeError,
        "Unsupported formula_or_cask type: #{formula_or_cask.class}"
end

Instance Method Details

#argsHomebrew::Cmd::Info::Args

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.



10
# File 'sorbet/rbi/dsl/homebrew/cmd/info.rbi', line 10

def args; end

#github_remote_path(remote, path) ⇒ 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:



143
144
145
146
147
148
149
# File 'cmd/info.rb', line 143

def github_remote_path(remote, path)
  if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$}
    "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/HEAD/#{path}"
  else
    "#{remote}/#{path}"
  end
end

#runvoid

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.



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
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'cmd/info.rb', line 91

def run
  if args.sizes?
    if args.no_named?
      print_sizes
    else
      formulae, casks = args.named.to_formulae_to_casks
      formulae = T.cast(formulae, T::Array[Formula])
      print_sizes(formulae:, casks:)
    end
  elsif args.analytics?
    if args.days.present? && VALID_DAYS.exclude?(args.days)
      raise UsageError, "`--days` must be one of #{VALID_DAYS.join(", ")}."
    end

    if args.category.present?
      if args.named.present? && VALID_FORMULA_CATEGORIES.exclude?(args.category)
        raise UsageError,
              "`--category` must be one of #{VALID_FORMULA_CATEGORIES.join(", ")} when querying formulae."
      end

      unless VALID_CATEGORIES.include?(args.category)
        raise UsageError, "`--category` must be one of #{VALID_CATEGORIES.join(", ")}."
      end
    end

    print_analytics
  elsif (json = args.json)
    print_json(json, args.eval_all?)
  elsif args.installed?
    T.let([
      *(args.cask? ? [] : Formula.installed.sort),
      *(args.formula? ? [] : Cask::Caskroom.casks.sort_by(&:full_name)),
    ], T::Array[T.any(Formula, Cask::Cask)]).each_with_index do |formula_or_cask, i|
      puts unless i.zero?

      info_formula_or_cask(formula_or_cask, quiet: !args.verbose?)
    end
  elsif args.github?
    raise FormulaOrCaskUnspecifiedError if args.no_named?

    exec_browser(*args.named.to_formulae_and_casks.map do |formula_keg_or_cask|
      formula_or_cask = T.cast(formula_keg_or_cask, T.any(Formula, Cask::Cask))
      github_info(formula_or_cask)
    end)
  elsif args.no_named?
    print_statistics
  else
    print_info(quiet: args.quiet?)
  end
end