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.
Instance Attribute Summary collapse
- #parent ⇒ Object readonly private
Instance Method Summary collapse
- #homebrew_tap_cask_names ⇒ Array<String> private
- #initialize(*args, parent: Args.new, override_spec: T.unsafe(nil), force_bottle: T.unsafe(nil), flags: T.unsafe(nil), cask_options: false, without_api: false) ⇒ void constructor private
- #to_casks ⇒ Object private
- #to_default_kegs ⇒ Array<Keg> private
- #to_formulae ⇒ Object private
- #to_formulae_and_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: T.unsafe(nil), uniq: true, warn: T.unsafe(nil)) ⇒ Array<Formula, Keg, Cask::Cask> private
- #to_formulae_and_casks_and_unavailable(only: parent&.only_formula_or_cask, method: nil) ⇒ Object private
- #to_formulae_to_casks(only: parent&.only_formula_or_cask, method: nil) ⇒ Object private
- #to_installed_taps ⇒ Array<Tap> private
- #to_kegs ⇒ Array<Keg> private
- #to_kegs_to_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, all_kegs: nil) ⇒ 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) ⇒ Object private
- #to_taps ⇒ Array<Tap> private
Methods inherited from Array
#blank?, #deep_dup, #fifth, #fourth, #present?, #second, #third, #to_sentence
Constructor Details
#initialize(*args, parent: Args.new, override_spec: T.unsafe(nil), force_bottle: T.unsafe(nil), flags: T.unsafe(nil), 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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'cli/named_args.rb', line 23 def initialize( *args, parent: Args.new, override_spec: T.unsafe(nil), force_bottle: T.unsafe(nil), flags: T.unsafe(nil), cask_options: false, without_api: false ) require "cask/cask" require "cask/cask_loader" require "formulary" require "keg" require "missing_formula" @args = args @override_spec = override_spec @force_bottle = force_bottle @flags = flags @cask_options = @without_api = without_api @parent = parent super(@args) end |
Instance Attribute Details
#parent ⇒ Object (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.
49 50 51 |
# File 'cli/named_args.rb', line 49 def parent @parent end |
Instance Method Details
#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.
337 338 339 |
# File 'cli/named_args.rb', line 337 def homebrew_tap_cask_names downcased_unique_named.grep(HOMEBREW_CASK_TAP_CASK_REGEX) end |
#to_casks ⇒ Object
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.
51 52 53 |
# File 'cli/named_args.rb', line 51 def to_casks @to_casks ||= to_formulae_and_casks(only: :cask).freeze 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.
276 277 278 279 280 281 282 283 284 285 |
# File 'cli/named_args.rb', line 276 def to_default_kegs @to_default_kegs ||= begin to_formulae_and_casks(only: :formula, method: :default_kegs).freeze rescue NoSuchKegError => e if (reason = MissingFormula.suggest_command(e.name, "uninstall")) $stderr.puts reason end raise e end end |
#to_formulae ⇒ Object
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.
55 56 57 |
# File 'cli/named_args.rb', line 55 def to_formulae @to_formulae ||= to_formulae_and_casks(only: :formula).freeze end |
#to_formulae_and_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: T.unsafe(nil), uniq: true, warn: T.unsafe(nil)) ⇒ 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.
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 |
# File 'cli/named_args.rb', line 71 def to_formulae_and_casks( only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: T.unsafe(nil), uniq: true, warn: T.unsafe(nil) ) @to_formulae_and_casks ||= {} @to_formulae_and_casks[only] ||= downcased_unique_named.flat_map do |name| = { warn: }.compact load_formula_or_cask(name, only:, method:, **) 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[only].uniq.freeze else @to_formulae_and_casks[only] end end |
#to_formulae_and_casks_and_unavailable(only: parent&.only_formula_or_cask, method: nil) ⇒ Object
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.
106 107 108 109 110 111 112 113 |
# File 'cli/named_args.rb', line 106 def to_formulae_and_casks_and_unavailable(only: parent&.only_formula_or_cask, method: nil) @to_formulae_casks_unknowns ||= {} @to_formulae_casks_unknowns[method] = downcased_unique_named.map do |name| load_formula_or_cask(name, only:, method:) rescue FormulaOrCaskUnavailableError => e e end.uniq.freeze end |
#to_formulae_to_casks(only: parent&.only_formula_or_cask, method: nil) ⇒ Object
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.
99 100 101 102 103 104 |
# File 'cli/named_args.rb', line 99 def to_formulae_to_casks(only: parent&.only_formula_or_cask, method: nil) @to_formulae_to_casks ||= {} @to_formulae_to_casks[[method, only]] = to_formulae_and_casks(only:, method:) .partition { |o| o.is_a?(Formula) || o.is_a?(Keg) } .map(&:freeze).freeze 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.
330 331 332 333 334 |
# File 'cli/named_args.rb', line 330 def to_installed_taps @to_installed_taps ||= to_taps.each do |tap| raise TapUnavailableError, tap.name unless tap.installed? end.uniq.freeze 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.
300 301 302 303 304 305 306 307 308 309 |
# File 'cli/named_args.rb', line 300 def to_kegs @to_kegs ||= begin to_formulae_and_casks(only: :formula, method: :kegs).freeze rescue NoSuchKegError => e if (reason = MissingFormula.suggest_command(e.name, "uninstall")) $stderr.puts reason end raise e end end |
#to_kegs_to_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, all_kegs: nil) ⇒ 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.
315 316 317 318 319 320 321 322 |
# File 'cli/named_args.rb', line 315 def to_kegs_to_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, all_kegs: nil) method = all_kegs ? :kegs : :default_kegs @to_kegs_to_casks ||= {} @to_kegs_to_casks[method] ||= to_formulae_and_casks(only:, ignore_unavailable:, method:) .partition { |o| o.is_a?(Keg) } .map(&:freeze).freeze 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.
288 289 290 291 292 293 294 295 296 297 |
# File 'cli/named_args.rb', line 288 def to_latest_kegs @to_latest_kegs ||= begin to_formulae_and_casks(only: :formula, method: :latest_kegs).freeze rescue NoSuchKegError => e if (reason = MissingFormula.suggest_command(e.name, "uninstall")) $stderr.puts reason end raise e end 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.
231 232 233 234 235 236 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 |
# File 'cli/named_args.rb', line 231 def to_paths(only: parent&.only_formula_or_cask, recurse_tap: false) @to_paths ||= {} @to_paths[only] ||= Homebrew.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 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.all_formulae.key?(path.basename.to_s)) paths << formula_path end if cask_path.exist? || (!Homebrew::EnvConfig.no_install_from_api? && !CoreCaskTap.instance.installed? && Homebrew::API::Cask.all_casks.key?(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.
214 215 216 217 |
# File 'cli/named_args.rb', line 214 def to_resolved_formulae(uniq: true) @to_resolved_formulae ||= to_formulae_and_casks(only: :formula, method: :resolve, uniq:) .freeze end |
#to_resolved_formulae_to_casks(only: parent&.only_formula_or_cask) ⇒ Object
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.
219 220 221 |
# File 'cli/named_args.rb', line 219 def to_resolved_formulae_to_casks(only: parent&.only_formula_or_cask) to_formulae_to_casks(only:, method: :resolve) 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.
325 326 327 |
# File 'cli/named_args.rb', line 325 def to_taps @to_taps ||= downcased_unique_named.map { |name| Tap.fetch name }.uniq.freeze end |