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, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #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>)


317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'cmd/info.rb', line 317

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:



218
219
220
221
222
223
224
# File 'cmd/info.rb', line 218

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:



199
200
201
202
203
# File 'cmd/info.rb', line 199

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:



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

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:



206
207
208
209
210
# File 'cmd/info.rb', line 206

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:



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'cmd/info.rb', line 227

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:

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'cmd/info.rb', line 156

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

  case formula_or_cask
  when Formula
    (formula_or_cask)
  when Cask::Cask
    if formula_or_cask.pinned?
      pinned = "Pinned: #{formula_or_cask.pinned_version}"
      if (pinned_time = pin_path_mtime(formula_or_cask.pin_path))
        pinned << " on #{formatted_time(pinned_time)}"
      end
      [pinned]
    else
      []
    end
  else
    T.absurd(formula_or_cask)
  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)


213
214
215
# File 'cmd/info.rb', line 213

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:

Returns:



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

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

  case formula_or_cask
  when Formula
    []
  when Cask::Cask
    cask_requirements_lines(formula_or_cask)
  else
    T.absurd(formula_or_cask)
  end
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:



147
148
149
150
151
152
153
# File 'cmd/info.rb', line 147

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.



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
141
142
143
144
# File 'cmd/info.rb', line 93

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)
    eval_all = args.eval_all?
    eval_all ||= args.no_named? && !args.installed? && Homebrew::EnvConfig.tap_trust_configured?
    print_json(json, 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