Class: Homebrew::Cmd::Info Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::Cmd::Info
- Extended by:
- 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
- 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
- #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 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_install_status, pretty_installed, pretty_removed, pretty_uninstalled, pretty_unmarked, pretty_upgradable, pretty_warning
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) ⇒ 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.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'cmd/info.rb', line 161 def self.installed_dependent_names(names) Formula.racks.filter_map do |rack| keg = Keg.from_rack(rack) next unless keg tab_path = keg/AbstractTab::FILENAME next unless tab_path.file? dependencies = begin keg.to_formula.runtime_dependencies(keg:) rescue FormulaUnavailableError, TapFormulaAmbiguityError, Homebrew::UntrustedTapError (keg.runtime_dependencies || []).filter_map do |dep| full_name = T.cast(dep, T::Hash[String, T.untyped])["full_name"] Dependency.new(full_name) if full_name end end dependent = dependencies.any? { names.include?(Utils.name_from_full_name(it.name)) } keg.name if dependent 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_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.
215 216 217 218 219 220 221 |
# File 'cmd/info.rb', line 215 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.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 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 |
# File 'cmd/info.rb', line 237 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.
152 153 154 155 156 157 158 |
# File 'cmd/info.rb', line 152 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.
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 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 |
# File 'cmd/info.rb', line 307 def info_formula(formula, shadowed_by: nil) 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 && formula.tap Utils.fully_qualified_name(formula) elsif shadowed_by formula.name else formula.full_name 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! 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 args.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 && formula.tap.present? && kegs.all? { |keg| keg.tab.tap == formula.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:, installation_status:, source_url: github_info(formula), tap: formula.tap, license: formula.license, installed_versions: installed_section_rows(shadowing_formula || formula, verbose: args.verbose?), verbose: args.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 installed_dependents = if $stdout.tty? && kegs.any? self.class.installed_dependent_names(formula.possible_names) else [].freeze 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 kegs.any? && type == "required" mark_uninstalled = kegs.any? && !optional_type "#{type.capitalize} (#{deps.count}): " \ "#{decorate_dependencies(deps, tab_runtime_deps: tab_deps, mark_uninstalled:, formula_outdated: outdated, missing_library_deps:)}" 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 installed_dependents.any? dependency_lines << if args.verbose? "Dependents (#{installed_dependents.count}): #{installed_dependents.join(", ")}" else "Dependents: #{installed_dependents.count}" 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: !args.verbose?) 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 - 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.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'cmd/info.rb', line 285 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 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.
224 225 226 227 228 229 230 231 232 233 234 |
# File 'cmd/info.rb', line 224 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.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'cmd/info.rb', line 186 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 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.
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 145 146 147 148 149 |
# File 'cmd/info.rb', line 100 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? 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? 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 |