Class: Homebrew::CLI::NamedArgs Private
- Inherits:
-
Array
- Object
- Array
- Homebrew::CLI::NamedArgs
- Extended by:
- T::Sig
- Defined in:
- brew/Library/Homebrew/cli/named_args.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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: nil, force_bottle: false, flags: []) ⇒ NamedArgs
constructor
private
A new instance of NamedArgs.
-
#to_casks ⇒ Object
private
-
#to_formulae ⇒ Object
private
- #to_formulae_and_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: 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_paths ⇒ 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_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 ⇒ Array<Formula>
private
-
#to_resolved_formulae_to_casks(only: parent&.only_formula_or_cask) ⇒ Object
private
-
#to_taps ⇒ Array<Tap>
private
Constructor Details
#initialize(*args, parent: Args.new, override_spec: nil, force_bottle: false, flags: []) ⇒ NamedArgs
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of NamedArgs.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 16 def initialize(*args, parent: Args.new, override_spec: nil, force_bottle: false, flags: []) 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 @parent = parent super(@args) end |
Instance Attribute Details
#parent ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 32 def parent @parent end |
Instance Method Details
#homebrew_tap_cask_names ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
202 203 204 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 202 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. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 34 def to_casks @to_casks ||= to_formulae_and_casks(only: :cask).freeze end |
#to_formulae ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 38 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: nil) ⇒ Array<Formula, Keg, Cask::Cask>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
49 50 51 52 53 54 55 56 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 49 def to_formulae_and_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: nil) @to_formulae_and_casks ||= {} @to_formulae_and_casks[only] ||= downcased_unique_named.flat_map do |name| load_formula_or_cask(name, only: only, method: method) rescue NoSuchKegError, FormulaUnavailableError, Cask::CaskUnavailableError ignore_unavailable ? [] : raise end.uniq.freeze end |
#to_formulae_and_casks_and_unavailable(only: parent&.only_formula_or_cask, method: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 68 69 70 71 72 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 65 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: only, method: method) rescue FormulaOrCaskUnavailableError => e e end.uniq.freeze end |
#to_formulae_paths ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
125 126 127 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 125 def to_formulae_paths to_paths(only: :formula) end |
#to_formulae_to_casks(only: parent&.only_formula_or_cask, method: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 61 62 63 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 58 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: only, method: method) .partition { |o| o.is_a?(Formula) } .map(&:freeze).freeze end |
#to_installed_taps ⇒ Array<Tap>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
195 196 197 198 199 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 195 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. You should avoid using this method if possible, as it may be removed or be changed in the future.
165 166 167 168 169 170 171 172 173 174 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 165 def to_kegs @to_kegs ||= begin to_formulae_and_casks(only: :formula, method: :keg).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. You should avoid using this method if possible, as it may be removed or be changed in the future.
180 181 182 183 184 185 186 187 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 180 def to_kegs_to_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, all_kegs: nil) method = all_kegs ? :kegs : :keg @to_kegs_to_casks ||= {} @to_kegs_to_casks[method] ||= to_formulae_and_casks(only: only, ignore_unavailable: ignore_unavailable, method: method) .partition { |o| o.is_a?(Keg) } .map(&:freeze).freeze end |
#to_paths(only: parent&.only_formula_or_cask, recurse_tap: false) ⇒ Array<Pathname>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 133 def to_paths(only: parent&.only_formula_or_cask, recurse_tap: false) @to_paths ||= {} @to_paths[only] ||= downcased_unique_named.flat_map do |name| if File.exist?(name) Pathname(name) elsif name.count("/") == 1 && !name.start_with?("./", "/") 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 = [] paths << formula_path if formula_path.exist? paths << cask_path if cask_path.exist? paths.empty? ? Pathname(name) : paths end end.uniq.freeze end |
#to_resolved_formulae ⇒ Array<Formula>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
116 117 118 119 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 116 def to_resolved_formulae @to_resolved_formulae ||= to_formulae_and_casks(only: :formula, method: :resolve) .freeze end |
#to_resolved_formulae_to_casks(only: parent&.only_formula_or_cask) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
121 122 123 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 121 def to_resolved_formulae_to_casks(only: parent&.only_formula_or_cask) to_formulae_to_casks(only: only, method: :resolve) end |
#to_taps ⇒ Array<Tap>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
190 191 192 |
# File 'brew/Library/Homebrew/cli/named_args.rb', line 190 def to_taps @to_taps ||= downcased_unique_named.map { |name| Tap.fetch name }.uniq.freeze end |