Class: Homebrew::Cmd::Info Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::Cmd::Info
- Extended by:
- Cacheable, T::Generic, Utils::Output::Mixin
- 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
- Cache =
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.
type_template { { fixed: T::Hash[Symbol, T::Array[Keg]] } }
- 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_categories.freeze, T::Array[String])
Class Method Summary collapse
Instance Method Summary collapse
- #args ⇒ Homebrew::Cmd::Info::Args private
- #formula_conflicts(formula) ⇒ Array<String> private
- #formula_qualified_by_user?(formula_or_cask, qualified_inputs) ⇒ Boolean private
- #github_info(formula_or_cask) ⇒ String private
- #github_remote_path(remote, path) ⇒ String private
- #info_formula(formula, shadowed_by: nil) ⇒ void private
- #info_formula_summary(formula) ⇒ void private
- #installed_resolution(formula) ⇒ Array<(Formula, [Tap, nil])> private
- #print_info(quiet: false) ⇒ void private
- #run ⇒ void private
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
Methods included from Cacheable
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Class Method Details
.installed_dependent_names(names, build: false) ⇒ 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.
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 |
# File 'cmd/info.rb', line 166 def self.installed_dependent_names(names, build: false) installed_kegs = cache[:installed_kegs] ||= Formula.racks.filter_map do |rack| keg = Keg.from_rack(rack) keg if keg && (keg/AbstractTab::FILENAME).file? rescue JSON::ParserError nil end installed_kegs.filter_map do |keg| # Only kegs built from source need their build dependencies again. next if build && keg.tab.poured_from_bottle dependency_names = if build keg.to_formula.deps.select(&:build?).map(&:name) elsif (tab_dependencies = keg.runtime_dependencies) # Loading every installed formula is slow, so read the receipt's list. tab_dependencies.filter_map { it["full_name"] } else keg.to_formula.runtime_dependencies(keg:).map(&:name) end keg.name if dependency_names.any? { names.include?(Utils.name_from_full_name(it)) } rescue FormulaUnavailableError, TapFormulaAmbiguityError, Homebrew::UntrustedTapError, JSON::ParserError nil end.sort.uniq end |
Instance Method Details
#args ⇒ Homebrew::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 |
#formula_conflicts(formula) ⇒ 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.
489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'cmd/info.rb', line 489 def formula_conflicts(formula) formula.conflicts.filter_map do |conflict| resolved = begin Formulary.factory(conflict.name) rescue FormulaUnavailableError nil end next if resolved && resolved.full_name == formula.full_name conflict_name = resolved&.full_name || conflict.name reason = " (because #{conflict.reason})" if conflict.reason "#{conflict_name}#{reason}" end.sort! end |
#formula_qualified_by_user?(formula_or_cask, qualified_inputs) ⇒ 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.
230 231 232 233 234 235 236 |
# File 'cmd/info.rb', line 230 def formula_qualified_by_user?(formula_or_cask, qualified_inputs) return false if qualified_inputs.empty? [formula_or_cask.full_name, Utils.fully_qualified_name(formula_or_cask)].any? do |name| qualified_inputs.include?(name.downcase) end end |
#github_info(formula_or_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.
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'cmd/info.rb', line 252 def github_info(formula_or_cask) tap = T.let(nil, T.nilable(Tap)) path = case formula_or_cask when Formula formula = formula_or_cask tap = formula.tap return formula.path.to_s if tap.blank? || tap.remote.blank? # The formula file may live outside the tap (e.g. loaded from a keg's # `.brew/` directory after the formula was removed from its tap), in # which case there is no meaningful upstream URL to link to. return formula.path.to_s unless formula.path.to_s.start_with?("#{tap.path}/") relative_path = formula.path.relative_path_from(tap.path) unless formula.loaded_from_api? @tracked_files ||= T.let({}, T.nilable(T::Hash[Tap, T::Set[String]])) @tracked_files[tap] ||= Utils.popen_read(Utils::Git.git, "-C", tap.path, "ls-files", "-z").split("\0").to_set if @tracked_files.fetch(tap).exclude?(relative_path.to_s) installed_path = formula.opt_prefix/".brew/#{formula.name}.rb" return installed_path.to_s if installed_path.file? && Tab.for_keg(formula.opt_prefix).tap == tap return formula.path.to_s end end relative_path when Cask::Cask cask = formula_or_cask tap = cask.tap return cask.sourcefile_path.to_s if tap.blank? || tap.remote.blank? sourcefile_path = cask.sourcefile_path if !sourcefile_path || sourcefile_path.extname != ".rb" return "#{tap.default_remote}/blob/HEAD/#{tap.relative_cask_path(cask.token)}" end return sourcefile_path.to_s unless sourcefile_path.to_s.start_with?("#{tap.path}/") sourcefile_path.relative_path_from(tap.path) end remote = tap.remote raise "unexpected nil tap.remote" unless remote github_remote_path(remote, path.to_s) 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.
157 158 159 160 161 162 163 |
# File 'cmd/info.rb', line 157 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 |
#info_formula(formula, shadowed_by: nil) ⇒ 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.
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 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'cmd/info.rb', line 323 def info_formula(formula, shadowed_by: nil) args = self.args verbose = args.verbose? tap = formula.tap shadowing_formula = shadowing_installed_formula(formula) kegs = shadowing_formula ? [] : formula.installed_kegs installed = kegs.any? outdated = installed && formula.outdated? stable = formula.stable stable_version = (outdated ? formula.pkg_version : stable.version).to_s if stable bottled = stable.present? && stable.bottled? && formula.pour_bottle? missing_libraries, missing_library_deps = if installed formula.missing_library_linkage else [[], Set.new] end installed_version = if outdated (formula.linked_version || kegs.max_by(&:scheme_and_version)&.version).to_s end title_name = if shadowing_formula && tap Utils.fully_qualified_name(formula) elsif shadowed_by formula.name else formula.full_name end heads, versioned = kegs.partition { |keg| keg.version.head? } kegs = [ *heads.sort_by { |keg| -keg.tab.time.to_i }, *versioned.sort_by(&:scheme_and_version), ] if kegs.empty? installation_status = ["Not installed"] if (bottle = formula.bottle) begin bottle.fetch_tab(quiet: !args.debug?) if verbose bottle_size = bottle.bottle_size installed_size = bottle.installed_size installation_status << "Bottle Size: #{Formatter.disk_usage_readable(bottle_size)}" if bottle_size if installed_size installation_status << "Installed Size: #{Formatter.disk_usage_readable(installed_size)}" end rescue RuntimeError => e odebug e end end else installation_status = [Utils::InfoDisplay.installation_status(Tab.for_formula(formula))] end puts Utils::InfoDisplay.package_summary( formula_or_cask: formula, title: Utils::InfoDisplay::Title.new( name: title_name, version: stable_version, installed_version:, installed:, outdated:, warning: missing_libraries.present?, removed: installed && tap.present? && kegs.all? { |keg| keg.tab.tap == tap && keg.deleted_formula? }, stable: stable.present?, bottled:, head: formula.head.present?, keg_only: formula.keg_only?, ), shadowed_by: shadowed_by&.name, aliases: formula.aliases, old_names: formula.oldnames, conflicts: formula_conflicts(formula), installation_status:, source_url: github_info(formula), tap:, license: formula.license, installed_versions: installed_section_rows(shadowing_formula || formula, verbose:), verbose:, ) tab_runtime_deps = kegs.last&.runtime_dependencies runtime_deps = if outdated formula.runtime_dependencies(read_from_tab: false, undeclared: false).map { { "full_name" => it.name } } else tab_runtime_deps end built_from_source = kegs.any? { |keg| !keg.tab.poured_from_bottle } installs_from_source = !installed && Utils::InfoDisplay.formula_installs_from_source?(formula) dependency_lines = %w[build required recommended optional].filter_map do |type| next if type == "build" && !built_from_source && !installs_from_source deps = formula.deps.public_send(type).uniq next if deps.empty? optional_type = ["recommended", "optional"].include?(type) tab_deps = tab_runtime_deps if installed && type == "required" mark_uninstalled = installed && !optional_type dependency_list = decorate_dependencies(deps, tab_runtime_deps: tab_deps, mark_uninstalled:, formula_outdated: outdated, missing_library_deps:) "#{type.capitalize} (#{deps.count}): #{dependency_list}" end missing_library_names = missing_libraries.map { |lib| File.basename(lib) }.uniq if missing_library_names.present? decorated = missing_library_names.map { |lib| pretty_uninstalled(lib, bold: false) }.join(", ") dependency_lines << "Missing libraries (#{missing_library_names.count}): #{decorated}" end if runtime_deps.present? installed_count = runtime_deps.count do |dep| dep_name = dep["full_name"]&.then { Utils.name_from_full_name(it) } next false unless dep_name Formula.rack_installed?(dep_name) end dependency_lines << Utils::InfoDisplay.recursive_runtime_line( installed_count, runtime_deps.count, mark_uninstalled: !outdated ) end if $stdout.tty? && kegs.any? { "Dependents" => false, "Build dependents" => true }.each do |type, build| names = self.class.installed_dependent_names(formula.possible_names, build:) next if names.empty? dependency_lines << if verbose "#{type} (#{names.count}): #{names.join(", ")}" else "#{type}: #{names.count}" end end end puts Utils::InfoDisplay.section("Dependencies", dependency_lines) if dependency_lines.present? requirements_section = Utils::InfoDisplay.requirements_section(formula.requirements.to_a, bold: true) puts requirements_section if requirements_section if !formula..empty? || formula.head ohai "Options" Options.dump_for_formula formula end caveats = Caveats.new(formula, shadowed_path: !verbose) if verbose binaries_keg = kegs.find(&:linked?) || kegs.last binaries = if binaries_keg binary_files = [binaries_keg/"bin", binaries_keg/"sbin"].select(&:directory?).flat_map do |dir| dir.children.select { |child| child.file? && child.executable? } end binary_files.map { |path| path.basename.to_s } elsif (path_exec_files = formula.bottle&.path_exec_files) path_exec_files.map { |path| File.basename(path) } end if binaries.present? binaries = binaries.sort.uniq - caveats.shadowed_path_executables.map(&:first) puts Utils::InfoDisplay.binaries_section(binaries, additional_text: caveats.shadowed_path_text) end end if (caveats_string = caveats.to_s.presence) ohai "Caveats", caveats_string end return unless formula.core_formula? Utils::Analytics.formula_output(formula, args:) end |
#info_formula_summary(formula) ⇒ 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.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'cmd/info.rb', line 300 def info_formula_summary(formula) kegs = formula.installed_kegs tab = Tab.for_formula(formula) version = kegs.sort_by(&:scheme_and_version) .map { |keg| keg.version.to_s } .join(", ") version = "-" if version.blank? puts oh1_title(info_summary_title(formula.full_name, formula.desc, installed: kegs.any?)) if kegs.empty? puts "Formula from #{github_info(formula)}" puts "Not installed" else source = formula.tap&.name || T.cast(tab.source["tap"], T.nilable(String)) || T.cast(tab.source["path"], T.nilable(String)) || github_info(formula) puts "Formula from #{source}" puts Utils::InfoDisplay.installation_summary(version, tab) end end |
#installed_resolution(formula) ⇒ Array<(Formula, [Tap, nil])>
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.
239 240 241 242 243 244 245 246 247 248 249 |
# File 'cmd/info.rb', line 239 def installed_resolution(formula) keg = formula.installed_kegs.last return [formula, nil] if keg.nil? installed_tap = keg.tab.tap return [formula, nil] if installed_tap.nil? || installed_tap == formula.tap [Formulary.factory("#{installed_tap}/#{keg.name}"), formula.tap] rescue FormulaUnavailableError, TapFormulaAmbiguityError [formula, nil] end |
#print_info(quiet: 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.
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 |
# File 'cmd/info.rb', line 193 def print_info(quiet: false) objects = args.named.to_formulae_and_casks_and_unavailable(method: :resolve_cask, uniq: false) user_qualified = args.named.downcased_unique_named.map { |name| name.include?("/") } resolved = user_qualified.zip(objects).map do |qualified, obj| if obj.is_a?(Formula) display_resolution(obj, user_qualified: qualified) else [obj, nil] end end resolved.uniq! do |obj, _shadowed_by| case obj when Formula, Cask::Cask then obj.full_name else obj end end resolved.each_with_index do |(obj, shadowed_by), i| puts unless i.zero? if obj.is_a?(FormulaOrCaskUnavailableError) # The formula/cask could not be found ofail obj. # No formula with this name, try a missing formula lookup require "missing_formula" if (reason = MissingFormula.reason(obj.name, show_info: true)) $stderr.puts reason end elsif obj.is_a?(Formula) || obj.is_a?(Cask::Cask) info_formula_or_cask(obj, quiet:, shadowed_by:) end end end |
#run ⇒ 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.
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 145 146 147 148 149 150 151 152 153 154 |
# File 'cmd/info.rb', line 105 def run if args.sizes? if args.no_named? print_sizes else formulae, casks = args.named.to_formulae_to_casks(method: :resolve_cask) 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.no_named? && !args.installed?) elsif args.installed? [ *(args.cask? ? [] : Formula.installed.sort), *(args.formula? ? [] : Cask::Caskroom.casks.sort_by(&:full_name)), ].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? Utils::Browser.open(*args.named.to_formulae_and_casks(method: :resolve_cask).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 |