Class: Homebrew::Cmd::TapInfo Private

Inherits:
AbstractCommand show all
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

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_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

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.

Parameters:

  • tap (Tap)
  • token (String)
  • installed (Boolean)

Returns:



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'cmd/tap-info.rb', line 152

def decorate_cask(tap, token, installed:)
  cask = Cask::CaskLoader.load("#{tap.name}/#{token}")
  incompatible = cask.incompatible?
  pretty_install_status(
    token,
    installed:,
    outdated:         installed && cask.outdated?,
    deprecated:       cask.deprecated?,
    disabled:         cask.disabled?,
    incompatible:,
    can_install:      cask.valid_platform? && !cask.disabled? && !incompatible,
    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.

Parameters:

  • tap (Tap)
  • name (String)
  • installed (Boolean)

Returns:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'cmd/tap-info.rb', line 134

def decorate_formula(tap, name, installed:)
  formula = Formulary.factory("#{tap.name}/#{name}")
  incompatible = formula.incompatible?
  pretty_install_status(
    name,
    installed:,
    outdated:         installed && formula.outdated?,
    deprecated:       formula.deprecated?,
    disabled:         formula.disabled?,
    incompatible:,
    can_install:      formula.valid_platform? && !formula.disabled? && !incompatible,
    mark_uninstalled: false,
  )
rescue
  pretty_install_status(name, installed:, mark_uninstalled: false)
end

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:



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
95
96
97
98
99
100
101
102
103
104
105
# 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"
    formula_count_label = Utils.pluralize("formula", formula_count, include_count: true)
    info += ", #{formula_count_label}"
    command_count_label = Utils.pluralize("command", command_count, include_count: true)
    info += ", #{command_count_label}"
    info += ", #{HOMEBREW_TAP_DIRECTORY.dup.abv}" if HOMEBREW_TAP_DIRECTORY.directory?
    puts info

    return
  end

  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"
        trust_status = Homebrew::Trust.trusted_tap?(tap) ? "Trusted" : "Untrusted"
        info += "\n#{trust_status}"
      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})"
      remote = tap.remote.presence || "N/A"
      info += "\nFrom: #{remote}"
      info += "\norigin: #{tap.remote}" if tap.remote != tap.default_remote
      head = tap.git_head || "(none)"
      info += "\nHEAD: #{head}"
      last_commit = tap.git_last_commit || "never"
      info += "\nlast commit: #{last_commit}"
      if default_branches.exclude?(tap.git_branch)
        branch = tap.git_branch || "(none)"
        info += "\nbranch: #{branch}"
      end
      puts info
      print_tap_listings(tap)
    else
      info += "Not installed"
      Homebrew.failed = true
      puts info
    end
  end
end

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:



170
171
172
173
174
175
# File 'cmd/tap-info.rb', line 170

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

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:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'cmd/tap-info.rb', line 108

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