Class: Homebrew::CLI::NamedArgs Private
Overview
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.
Helper class for loading formulae/casks from named arguments.
Constant Summary collapse
- Elem =
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.
type_member(:out) { { fixed: String } }
Instance Attribute Summary collapse
- #parent ⇒ Args readonly private
Instance Method Summary collapse
- #downcased_unique_named ⇒ Array<String> private
- #homebrew_tap_cask_names ⇒ Array<String> private
- #initialize(*args, parent: Args.new, override_spec: nil, force_bottle: false, flags: [], cask_options: false, without_api: false) ⇒ void constructor private
- #to_casks ⇒ Array<Cask::Cask> private
- #to_default_kegs ⇒ Array<Keg> private
- #to_formulae ⇒ Array<Formula> private
- #to_formulae_and_casks(only: parent.only_formula_or_cask, ignore_unavailable: false, method: nil, uniq: true, warn: false) ⇒ Array<Formula, Keg, Cask::Cask> private
- #to_formulae_and_casks_and_unavailable(only: parent.only_formula_or_cask, method: nil, uniq: true) ⇒ Array<Formula, Keg, Cask::Cask, Array<Keg>, FormulaOrCaskUnavailableError, NoSuchKegError> private
-
#to_formulae_and_casks_with_taps ⇒ Array<Formula, Keg, Cask::Cask>
private
Returns formulae and casks after validating that a tap is present for each of them.
- #to_formulae_to_casks(only: parent.only_formula_or_cask, method: nil) ⇒ Array<(Array<Formula, Keg>, Array<Cask::Cask>)> private
- #to_installed_taps ⇒ Array<Tap> private
- #to_kegs ⇒ Array<Keg> private
- #to_kegs_to_casks(only: parent.only_formula_or_cask, ignore_unavailable: false, method: :default_kegs) ⇒ Array<(Array<Keg>, Array<Cask::Cask>)> private
- #to_latest_kegs ⇒ Array<Keg> private
-
#to_paths(only: parent.only_formula_or_cask, recurse_tap: false) ⇒ Array<Pathname>
private
Keep existing paths and try to convert others to tap, formula or cask paths.
- #to_resolved_formulae(uniq: true) ⇒ Array<Formula> private
- #to_resolved_formulae_to_casks(only: parent.only_formula_or_cask) ⇒ Array<(Array<Formula>, Array<Cask::Cask>)> private
- #to_taps ⇒ Array<Tap> 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_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Methods inherited from Array
#blank?, #deep_dup, #fifth, #fourth, #present?, #second, #third
Constructor Details
#initialize(*args, parent: Args.new, override_spec: nil, force_bottle: false, flags: [], cask_options: false, without_api: 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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'cli/named_args.rb', line 32 def initialize( *args, parent: Args.new, override_spec: nil, force_bottle: false, flags: [], cask_options: false, without_api: false ) super(args) @override_spec = override_spec @force_bottle = force_bottle @flags = flags @cask_options = @without_api = without_api @parent = parent end |
Instance Attribute Details
#parent ⇒ Args (readonly)
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.
19 20 21 |
# File 'cli/named_args.rb', line 19 def parent @parent end |
Instance Method Details
#downcased_unique_named ⇒ 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.
304 305 306 307 308 309 310 311 312 313 |
# File 'cli/named_args.rb', line 304 def downcased_unique_named # Only lowercase names, not paths, bottle filenames or URLs map do |arg| if arg.include?("/") || arg.end_with?(".tar.gz") || File.exist?(arg) arg else arg.downcase end end.uniq end |
#homebrew_tap_cask_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.
299 300 301 |
# File 'cli/named_args.rb', line 299 def homebrew_tap_cask_names downcased_unique_named.grep(HOMEBREW_CASK_TAP_CASK_REGEX) end |
#to_casks ⇒ Array<Cask::Cask>
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.
52 53 54 55 56 57 |
# File 'cli/named_args.rb', line 52 def to_casks @to_casks ||= T.let( to_formulae_and_casks(only: :cask).freeze, T.nilable(T::Array[T.any(Formula, Keg, Cask::Cask)]) ) T.cast(@to_casks, T::Array[Cask::Cask]) end |
#to_default_kegs ⇒ Array<Keg>
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.
239 240 241 |
# File 'cli/named_args.rb', line 239 def to_default_kegs @to_default_kegs ||= T.let(formula_kegs(:default_kegs), T.nilable(T::Array[Keg])) end |
#to_formulae ⇒ Array<Formula>
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.
60 61 62 63 64 65 |
# File 'cli/named_args.rb', line 60 def to_formulae @to_formulae ||= T.let( to_formulae_and_casks(only: :formula).freeze, T.nilable(T::Array[T.any(Formula, Keg, Cask::Cask)]) ) T.cast(@to_formulae, T::Array[Formula]) end |
#to_formulae_and_casks(only: parent.only_formula_or_cask, ignore_unavailable: false, method: nil, uniq: true, warn: false) ⇒ Array<Formula, Keg, Cask::Cask>
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.
Convert named arguments to Formula or Cask objects.
If both a formula and cask with the same name exist, returns
the formula and prints a warning unless only is specified.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'cli/named_args.rb', line 79 def to_formulae_and_casks( only: parent.only_formula_or_cask, ignore_unavailable: false, method: nil, uniq: true, warn: false ) @to_formulae_and_casks ||= T.let( {}, T.nilable(T::Hash[T.nilable(Symbol), T::Array[T.any(Formula, Keg, Cask::Cask)]]) ) @to_formulae_and_casks[only] ||= downcased_unique_named.flat_map do |name| load_formula_or_cask(name, only:, method:, warn:) rescue FormulaUnreadableError, FormulaClassUnavailableError, TapFormulaUnreadableError, TapFormulaClassUnavailableError, Cask::CaskUnreadableError # Need to rescue before `*UnavailableError` (superclass of this) # The formula/cask was found, but there's a problem with its implementation raise rescue NoSuchKegError, FormulaUnavailableError, Cask::CaskUnavailableError, FormulaOrCaskUnavailableError ignore_unavailable ? [] : raise end.freeze if uniq @to_formulae_and_casks.fetch(only).uniq.freeze else @to_formulae_and_casks.fetch(only) end end |
#to_formulae_and_casks_and_unavailable(only: parent.only_formula_or_cask, method: nil, uniq: true) ⇒ Array<Formula, Keg, Cask::Cask, Array<Keg>, FormulaOrCaskUnavailableError, NoSuchKegError>
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.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'cli/named_args.rb', line 149 def to_formulae_and_casks_and_unavailable(only: parent.only_formula_or_cask, method: nil, uniq: true) @to_formulae_casks_unknowns ||= T.let( {}, T.nilable(T::Hash[ [T.nilable(Symbol), T::Boolean], T::Array[T.any(Formula, Keg, Cask::Cask, T::Array[Keg], FormulaOrCaskUnavailableError, NoSuchKegError)], ]), ) items = downcased_unique_named.map do |name| load_formula_or_cask(name, only:, method:) rescue FormulaOrCaskUnavailableError, NoSuchKegError => e e end items = items.uniq if uniq @to_formulae_casks_unknowns[[method, uniq]] = items.freeze end |
#to_formulae_and_casks_with_taps ⇒ Array<Formula, Keg, Cask::Cask>
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.
Returns formulae and casks after validating that a tap is present for each of them.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'cli/named_args.rb', line 122 def to_formulae_and_casks_with_taps formulae_and_casks_with_taps, formulae_and_casks_without_taps = to_formulae_and_casks.partition do |formula_or_cask| T.cast(formula_or_cask, T.any(Formula, Cask::Cask)).tap&.installed? end return formulae_and_casks_with_taps if formulae_and_casks_without_taps.empty? types = [] types << "formulae" if formulae_and_casks_without_taps.any?(Formula) types << "casks" if formulae_and_casks_without_taps.any?(Cask::Cask) package_names = formulae_and_casks_without_taps.sort_by(&:to_s).join("\n ") odie <<~ERROR These #{types.join(" and ")} are not in any locally installed taps! #{package_names} You may need to run `brew tap` to install additional taps. ERROR end |
#to_formulae_to_casks(only: parent.only_formula_or_cask, method: nil) ⇒ Array<(Array<Formula, Keg>, Array<Cask::Cask>)>
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.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'cli/named_args.rb', line 108 def to_formulae_to_casks(only: parent.only_formula_or_cask, method: nil) @to_formulae_to_casks ||= T.let( {}, T.nilable(T::Hash[[T.nilable(Symbol), T.nilable(Symbol)], [T::Array[T.any(Formula, Keg)], T::Array[Cask::Cask]]]) ) partitioned = to_formulae_and_casks(only:, method:).partition { |o| o.is_a?(Formula) || o.is_a?(Keg) } .map(&:freeze) .freeze @to_formulae_to_casks[[method, only]] = T.cast(partitioned, [T::Array[T.any(Formula, Keg)], T::Array[Cask::Cask]]) end |
#to_installed_taps ⇒ Array<Tap>
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.
288 289 290 291 292 293 294 295 296 |
# File 'cli/named_args.rb', line 288 def to_installed_taps return @to_installed_taps if @to_installed_taps to_installed_taps = to_taps.each do |tap| raise TapUnavailableError, tap.name unless tap.installed? end.uniq.freeze @to_installed_taps = T.let(to_installed_taps, T.nilable(T::Array[Tap])) to_installed_taps end |
#to_kegs ⇒ Array<Keg>
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.
249 250 251 |
# File 'cli/named_args.rb', line 249 def to_kegs @to_kegs ||= T.let(formula_kegs(:kegs), T.nilable(T::Array[Keg])) end |
#to_kegs_to_casks(only: parent.only_formula_or_cask, ignore_unavailable: false, method: :default_kegs) ⇒ Array<(Array<Keg>, Array<Cask::Cask>)>
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.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'cli/named_args.rb', line 257 def to_kegs_to_casks(only: parent.only_formula_or_cask, ignore_unavailable: false, method: :default_kegs) key = [method, only, ignore_unavailable] @to_kegs_to_casks ||= T.let( {}, T.nilable( T::Hash[ [T.nilable(Symbol), T.nilable(Symbol), T::Boolean], [T::Array[Keg], T::Array[Cask::Cask]], ], ), ) @to_kegs_to_casks[key] ||= begin partitioned = to_formulae_and_casks(only:, ignore_unavailable:, method:) .partition { |o| o.is_a?(Keg) } .map(&:freeze) .freeze T.cast(partitioned, [T::Array[Keg], T::Array[Cask::Cask]]) end end |
#to_latest_kegs ⇒ Array<Keg>
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.
244 245 246 |
# File 'cli/named_args.rb', line 244 def to_latest_kegs @to_latest_kegs ||= T.let(formula_kegs(:latest_kegs), T.nilable(T::Array[Keg])) end |
#to_paths(only: parent.only_formula_or_cask, recurse_tap: false) ⇒ Array<Pathname>
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.
Keep existing paths and try to convert others to tap, formula or cask paths.
If a cask and formula with the same name exist, includes both their paths
unless only is specified.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'cli/named_args.rb', line 189 def to_paths(only: parent.only_formula_or_cask, recurse_tap: false) require "api/env" @to_paths ||= T.let({}, T.nilable(T::Hash[T.nilable(Symbol), T::Array[Pathname]])) @to_paths[only] ||= Homebrew::API.with_no_api_env_if_needed(@without_api) do downcased_unique_named.flat_map do |name| path = Pathname(name). if only.nil? && name.match?(LOCAL_PATH_REGEX) && path.exist? path elsif name.match?(TAP_NAME_REGEX) tap = Tap.fetch(name) if recurse_tap next tap.formula_files if only == :formula next tap.cask_files if only == :cask end tap.path else next Formulary.path(name) if only == :formula require "cask/cask_loader" next Cask::CaskLoader.path(name) if only == :cask formula_path = Formulary.path(name) cask_path = Cask::CaskLoader.path(name) paths = [] if formula_path.exist? || (!Homebrew::EnvConfig.no_install_from_api? && !CoreTap.instance.installed? && Homebrew::API.formula_name?(path.basename.to_s)) paths << formula_path end if cask_path.exist? || (CoreCaskTap.instance.use_api? && !CoreCaskTap.instance.installed? && Homebrew::API.cask_token?(path.basename.to_s)) paths << cask_path end paths.empty? ? path : paths end end.uniq.freeze end end |
#to_resolved_formulae(uniq: true) ⇒ Array<Formula>
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.
168 169 170 171 172 173 174 |
# File 'cli/named_args.rb', line 168 def to_resolved_formulae(uniq: true) unless @to_resolved_formulae formulae = to_formulae_and_casks(only: :formula, method: :resolve, uniq:).freeze @to_resolved_formulae = T.let(formulae, T.nilable(T::Array[T.any(Formula, Keg, Cask::Cask)])) end T.cast(@to_resolved_formulae, T::Array[Formula]) end |
#to_resolved_formulae_to_casks(only: parent.only_formula_or_cask) ⇒ Array<(Array<Formula>, Array<Cask::Cask>)>
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.
177 178 179 |
# File 'cli/named_args.rb', line 177 def to_resolved_formulae_to_casks(only: parent.only_formula_or_cask) T.cast(to_formulae_to_casks(only:, method: :resolve), [T::Array[Formula], T::Array[Cask::Cask]]) end |
#to_taps ⇒ Array<Tap>
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.
279 280 281 282 283 284 285 |
# File 'cli/named_args.rb', line 279 def to_taps return @to_taps if @to_taps to_taps = downcased_unique_named.map { |name| Tap.fetch name }.uniq.freeze @to_taps = T.let(to_taps, T.nilable(T::Array[Tap])) to_taps end |