Class: Homebrew::Cmd::TapInfo Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::Cmd::TapInfo
- Defined in:
- cmd/tap-info.rb,
sorbet/rbi/dsl/homebrew/cmd/tap_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
Instance Method Summary collapse
- #args ⇒ Homebrew::Cmd::TapInfo::Args private
- #decorate_cask(tap, token, installed:) ⇒ String private
- #decorate_formula(tap, name, installed:) ⇒ String private
- #print_tap_info(taps) ⇒ void private
- #print_tap_json(taps) ⇒ void private
- #print_tap_listings(tap) ⇒ 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
Instance Method Details
#args ⇒ Homebrew::Cmd::TapInfo::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/tap_info.rbi', line 10 def args; end |
#decorate_cask(tap, token, installed:) ⇒ 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.
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'cmd/tap-info.rb', line 138 def decorate_cask(tap, token, installed:) cask = Cask::CaskLoader.load("#{tap.name}/#{token}") pretty_install_status( token, installed:, outdated: installed && cask.outdated?, deprecated: cask.deprecated?, disabled: cask.disabled?, mark_uninstalled: false, ) rescue pretty_install_status(token, installed:, mark_uninstalled: false) end |
#decorate_formula(tap, name, installed:) ⇒ 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.
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'cmd/tap-info.rb', line 123 def decorate_formula(tap, name, installed:) formula = Formulary.factory("#{tap.name}/#{name}") pretty_install_status( name, installed:, outdated: installed && formula.outdated?, deprecated: formula.deprecated?, disabled: formula.disabled?, mark_uninstalled: false, ) rescue pretty_install_status(name, installed:, mark_uninstalled: false) end |
#print_tap_info(taps) ⇒ 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.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'cmd/tap-info.rb', line 44 def print_tap_info(taps) if taps.none? # Tap#private? queries the GitHub API for each non-core tap. tap_stats = Utils.parallel_map(Tap.installed) do |tap| [tap.formula_files.size, tap.command_files.size, tap.private?] end tap_count = tap_stats.count formula_count = tap_stats.sum(&:first) command_count = tap_stats.sum { |_, command_files_count, _| command_files_count } private_count = tap_stats.count { |_, _, private_tap| private_tap } info = Utils.pluralize("tap", tap_count, include_count: true) info += ", #{private_count} private" info += ", #{Utils.pluralize("formula", formula_count, include_count: true)}" info += ", #{Utils.pluralize("command", command_count, include_count: true)}" info += ", #{HOMEBREW_TAP_DIRECTORY.dup.abv}" if HOMEBREW_TAP_DIRECTORY.directory? puts info else info = "" default_branches = %w[main master].freeze taps.each_with_index do |tap, i| puts unless i.zero? info = "#{tap}: " if tap.installed? info += "Installed" if Homebrew::EnvConfig.require_tap_trust? require "trust" info += "\n#{Homebrew::Trust.trusted_tap?(tap) ? "Trusted" : "Untrusted"}" end info += if (contents = tap.contents).blank? "\nNo commands/casks/formulae" else "\n#{contents.join(", ")}" end info += "\nPrivate" if tap.private? info += "\n#{tap.path} (#{tap.path.abv})" info += "\nFrom: #{tap.remote.presence || "N/A"}" info += "\norigin: #{tap.remote}" if tap.remote != tap.default_remote info += "\nHEAD: #{tap.git_head || "(none)"}" info += "\nlast commit: #{tap.git_last_commit || "never"}" info += "\nbranch: #{tap.git_branch || "(none)"}" if default_branches.exclude?(tap.git_branch) puts info print_tap_listings(tap) else info += "Not installed" Homebrew.failed = true puts info end end end end |
#print_tap_json(taps) ⇒ 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.
153 154 155 156 157 158 |
# File 'cmd/tap-info.rb', line 153 def print_tap_json(taps) # Tap#to_hash shells out to Git and queries the GitHub API. hashes = Utils.parallel_map(taps, &:to_hash) puts JSON.pretty_generate(hashes) end |
#print_tap_listings(tap) ⇒ 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.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'cmd/tap-info.rb', line 97 def print_tap_listings(tap) commands = tap.command_files .map { |path| path.basename(path.extname).to_s.delete_prefix("brew-") } .sort installed_formula_names = Formula.installed_formula_names.to_set installed_cask_tokens = Cask::Caskroom.tokens.to_set formula_names = tap.formula_names.map { |name| Utils.name_from_full_name(name) }.sort cask_tokens = tap.cask_tokens.map { |token| Utils.name_from_full_name(token) }.sort installed_formulae = formula_names.select { |name| installed_formula_names.include?(name) } installed_casks = cask_tokens.select { |token| installed_cask_tokens.include?(token) } if commands.any? ohai "Commands" puts commands.join(", ") end min_width = (formula_names + cask_tokens).map { |n| Tty.strip_ansi(pretty_uninstalled(n)).length }.max || 0 print_section(tap, "Formulae", formula_names, installed_formulae, min_width:) do |name| decorate_formula(tap, name, installed: installed_formula_names.include?(name)) end print_section(tap, "Casks", cask_tokens, installed_casks, min_width:) do |token| decorate_cask(tap, token, installed: installed_cask_tokens.include?(token)) 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.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'cmd/tap-info.rb', line 25 def run require "tap" taps = if args.installed? Tap else args.named.to_taps end if args.json raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json print_tap_json(taps.sort_by(&:to_s)) else print_tap_info(taps.sort_by(&:to_s)) end end |