Class: Homebrew::Cmd::Info Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::Cmd::Info
- 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
- .collect_cask_dependency_names(cask, formula_dependencies, cask_dependencies, visited_casks) ⇒ void private
- .dependency_status_counts(installed_count, total_count) ⇒ String private
- .installation_reason(tab) ⇒ String private
- .installation_status(tab) ⇒ String private
- .installation_summary(version, tab) ⇒ String private
- .installed_dependent_names(full_name, name) ⇒ Array<String> private
- .metadata_lines(formula_or_cask) ⇒ Array<String> private
- .requirement_for_other_os?(requirement) ⇒ Boolean private
Instance Method Summary collapse
- #args ⇒ Homebrew::Cmd::Info::Args 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 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_unmarked, #pretty_upgradable, #pretty_warning
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.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'cmd/info.rb', line 282 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.
204 205 206 207 208 209 210 |
# File 'cmd/info.rb', line 204 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.
185 186 187 188 189 |
# File 'cmd/info.rb', line 185 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.
178 179 180 181 182 |
# File 'cmd/info.rb', line 178 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.
192 193 194 195 196 |
# File 'cmd/info.rb', line 192 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.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'cmd/info.rb', line 213 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.
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.
199 200 201 |
# File 'cmd/info.rb', line 199 def self.requirement_for_other_os?(requirement) requirement.instance_of?(MacOSRequirement) || requirement.instance_of?(LinuxRequirement) 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_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.
347 348 349 350 351 352 353 354 355 |
# File 'cmd/info.rb', line 347 def formula_qualified_by_user?(formula_or_cask, qualified_inputs) return false if qualified_inputs.empty? names = T.let([formula_or_cask.full_name.downcase], T::Array[String]) if (tap = formula_or_cask.tap) names << "#{tap.name.downcase}/#{Utils.name_or_token(formula_or_cask).downcase}" end names.any? { |n| qualified_inputs.include?(n) } 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.
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 |
# File 'cmd/info.rb', line 371 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}/") formula.path.relative_path_from(tap.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 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.
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 |
#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.
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 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'cmd/info.rb', line 426 def info_formula(formula, shadowed_by: nil) specs = T.let([], T::Array[String]) if (stable = formula.stable) string = "stable #{stable.version}" string += " (bottled)" if stable.bottled? && formula.pour_bottle? specs << string end specs << "HEAD" if formula.head attrs = [] attrs << "keg-only" if formula.keg_only? shadowing_formula = shadowing_installed_formula(formula) kegs = shadowing_formula ? [] : formula.installed_kegs installed = kegs.any? outdated = installed && formula.outdated? missing_libraries, missing_library_deps = formula.missing_library_linkage if installed missing_libraries ||= [] missing_library_deps ||= Set.new if outdated && (upgrade_version = specs.first.presence) installed_version = formula.linked_version || kegs.max_by(&:scheme_and_version)&.version specs[0] = "#{installed_version} → #{upgrade_version}" end title_name = if shadowing_formula && (formula_tap = formula.tap) "#{formula_tap}/#{formula.name}" elsif shadowed_by formula.name else formula.full_name end name_with_status = pretty_install_status( title_name, warning: missing_libraries.present?, installed:, outdated:, deprecated: formula.deprecated?, disabled: formula.disabled?, bold: true, ) puts "#{oh1_title(name_with_status)}: #{specs * ", "}#{" [#{attrs * ", "}]" unless attrs.empty?}" if shadowed_by puts Formatter.warning( "`#{formula.name}` shadows `#{shadowed_by.name}/#{formula.name}`.", label: "Warning", ) end puts formula.desc if formula.desc puts Formatter.url(formula.homepage) if formula.homepage puts "Aliases: #{formula.aliases.join(", ")}" if formula.aliases.any? puts "Old Names: #{formula.oldnames.join(", ")}" if formula.oldnames.any? deprecate_disable_info_string = DeprecateDisable.(formula) if deprecate_disable_info_string.present? deprecate_disable_info_string.tap { |info_string| info_string[0] = info_string[0].upcase } puts deprecate_disable_info_string end conflicts = 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! unless conflicts.empty? puts <<~EOS Conflicts with: #{conflicts.join("\n ")} EOS 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? puts "Not installed" if (bottle = formula.bottle) begin bottle.fetch_tab(quiet: !args.debug?) if args.fetch_manifest? || args.verbose? bottle_size = bottle.bottle_size installed_size = bottle.installed_size puts "Bottle Size: #{Formatter.disk_usage_readable(bottle_size)}" if bottle_size puts "Installed Size: #{Formatter.disk_usage_readable(installed_size)}" if installed_size rescue RuntimeError => e odebug e end end else puts self.class.installation_status(Tab.for_formula(formula)) end puts "From: #{Formatter.url(github_info(formula))}" formula_tap = formula.tap puts "Tap: #{formula_tap.name}" if formula_tap && !formula_tap.official? puts "License: #{SPDX.license_expression_to_string formula.license}" if formula.license.present? = self.class.(formula) puts if .present? installed_lines = installed_section_lines(shadowing_formula || formula, verbose: args.verbose?) unless installed_lines.empty? ohai(args.verbose? ? "Installed Kegs and Versions" : "Installed Versions") installed_lines.each { |line| puts line } end tab_runtime_deps = kegs.last&.runtime_dependencies installed_dependents = if $stdout.tty? && kegs.any? self.class.installed_dependent_names(formula.full_name, formula.name) else [].freeze end dependency_lines = %w[build required recommended optional].filter_map do |type| next if type == "build" && (kegs.all? { |keg| keg.tab.poured_from_bottle } || (kegs.empty? && (formula.requirements.any? { |requirement| self.class.requirement_for_other_os?(requirement) } || (stable.present? ? stable.bottled? && formula.pour_bottle? : formula.head.blank?)))) deps = formula.deps.send(type).uniq next if deps.empty? tab_deps = (kegs.any? && type != "build") ? tab_runtime_deps : nil "#{type.capitalize} (#{deps.count}): " \ "#{decorate_dependencies(deps, tab_runtime_deps: tab_deps, mark_uninstalled: kegs.any?, missing_library_deps:)}" end if dependency_lines.present? || tab_runtime_deps.present? || installed_dependents.any? ohai "Dependencies" puts dependency_lines 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(", ") puts "Missing libraries (#{missing_library_names.count}): #{decorated}" end if tab_runtime_deps.present? installed_count = tab_runtime_deps.count do |dep| dep_name = dep["full_name"]&.then { Utils.name_from_full_name(it) } next false unless dep_name rack = HOMEBREW_CELLAR/dep_name rack.directory? && !rack.subdirs.empty? end puts "Recursive Runtime (#{tab_runtime_deps.count}): " \ "#{self.class.dependency_status_counts(installed_count, tab_runtime_deps.count)}" end if installed_dependents.any? if args.verbose? puts "Dependents (#{installed_dependents.count}): #{installed_dependents.join(", ")}" else puts "Dependents: #{installed_dependents.count}" end end end unless formula.requirements.to_a.empty? ohai "Requirements" %w[build required recommended optional].map do |type| reqs = formula.requirements.select(&:"#{type}?") next if reqs.to_a.empty? puts "#{type.capitalize}: #{decorate_requirements(reqs, mark_uninstalled: kegs.any?)}" end end if !formula..empty? || formula.head ohai "Options" Options.dump_for_formula formula end if args.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 ohai "Binaries", Formatter.columns(binaries) end end caveats = Caveats.new(formula) 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.
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'cmd/info.rb', line 404 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 puts "Formula from #{formula.tap&.name || T.cast(tab.source["tap"], T.nilable(String)) || T.cast(tab.source["path"], T.nilable(String)) || github_info(formula)}" puts self.class.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.
358 359 360 361 362 363 364 365 366 367 368 |
# File 'cmd/info.rb', line 358 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.
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 |
# File 'cmd/info.rb', line 318 def print_info(quiet: false) objects = args.named.to_formulae_and_casks_and_unavailable(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 unique_by_display_name(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 if (reason = MissingFormula.reason(obj.name, show_info: true)) $stderr.puts reason end else 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.
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 |