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
- .count_installed_dependents(full_name, name) ⇒ Integer private
- .dependency_status_counts(installed_count, total_count) ⇒ String private
- .installation_status(tab) ⇒ String private
- .metadata_lines(formula_or_cask) ⇒ Array<String> private
- .requirement_for_other_os?(requirement) ⇒ Boolean private
- .requirements_lines(formula_or_cask) ⇒ Array<String> private
Instance Method Summary collapse
- #args ⇒ Homebrew::Cmd::Info::Args private
- #github_remote_path(remote, path) ⇒ String private
- #run ⇒ void private
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Methods included from Utils::Output::Mixin
#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled
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.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'cmd/info.rb', line 275 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/dep_name.split("/").last 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 |
.count_installed_dependents(full_name, name) ⇒ Integer
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'cmd/info.rb', line 185 def self.count_installed_dependents(full_name, name) Formula.racks.count do |rack| keg = Keg.from_rack(rack) next false unless keg tab_path = keg/AbstractTab::FILENAME next false 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 false unless content.include?(name) tab_deps = Tab.from_file_content(content, tab_path).runtime_dependencies next false unless tab_deps 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&.split("/")&.last == name 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.
179 180 181 182 |
# File 'cmd/info.rb', line 179 def self.dependency_status_counts(installed_count, total_count) "#{installed_count} #{Formatter.success("✔")}, " \ "#{total_count - installed_count} #{Formatter.error("✘")}" 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.
167 168 169 170 171 |
# File 'cmd/info.rb', line 167 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 |
.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.
142 143 144 145 146 147 148 149 150 151 152 |
# File 'cmd/info.rb', line 142 def self.(formula_or_cask) return [] unless $stdout.tty? if formula_or_cask.is_a?(Formula) || formula_or_cask.respond_to?(:pinned?) (formula_or_cask) elsif formula_or_cask.is_a?(Cask::Cask) || formula_or_cask.respond_to?(:supports_macos?) [] else raise TypeError, "Unsupported formula_or_cask type: #{formula_or_cask.class}" 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.
174 175 176 |
# File 'cmd/info.rb', line 174 def self.requirement_for_other_os?(requirement) requirement.instance_of?(MacOSRequirement) || requirement.instance_of?(LinuxRequirement) end |
.requirements_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.
155 156 157 158 159 160 161 162 163 164 |
# File 'cmd/info.rb', line 155 def self.requirements_lines(formula_or_cask) return [] unless $stdout.tty? return [] if formula_or_cask.is_a?(Formula) || formula_or_cask.respond_to?(:pinned?) if formula_or_cask.is_a?(Cask::Cask) || formula_or_cask.respond_to?(:supports_macos?) return cask_requirements_lines(formula_or_cask) end raise TypeError, "Unsupported formula_or_cask type: #{formula_or_cask.class}" 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 |
#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.
133 134 135 136 137 138 139 |
# File 'cmd/info.rb', line 133 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 |
#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.
90 91 92 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 |
# File 'cmd/info.rb', line 90 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) print_json(json, args.eval_all?) 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 end end |