Class: Homebrew::CLI::NamedArgs Private
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Homebrew::CLI::NamedArgs
- Defined in:
- 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 Method Summary collapse
-
#homebrew_tap_cask_names ⇒ Object
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: nil, method: nil) ⇒ Object
private
-
#to_formulae_and_casks_and_unavailable(method: nil) ⇒ Object
private
-
#to_formulae_paths ⇒ Object
private
-
#to_formulae_to_casks(method: nil, only: nil) ⇒ Object
private
-
#to_kegs ⇒ Object
private
-
#to_kegs_to_casks ⇒ Object
private
-
#to_paths(only: nil) ⇒ Object
private
Keep existing paths and try to convert others to tap, formula or cask paths.
-
#to_resolved_formulae ⇒ Object
private
-
#to_resolved_formulae_to_casks(only: nil) ⇒ Object
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.
17 18 19 20 21 22 23 24 25 |
# File 'Library/Homebrew/cli/named_args.rb', line 17 def initialize(*args, parent: Args.new, override_spec: nil, force_bottle: false, flags: []) @args = args @override_spec = override_spec @force_bottle = force_bottle @flags = flags @parent = parent super(@args) end |
Instance Method Details
#homebrew_tap_cask_names ⇒ 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.
179 180 181 |
# File 'Library/Homebrew/cli/named_args.rb', line 179 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.
27 28 29 |
# File 'Library/Homebrew/cli/named_args.rb', line 27 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.
31 32 33 |
# File 'Library/Homebrew/cli/named_args.rb', line 31 def to_formulae @to_formulae ||= to_formulae_and_casks(only: :formula).freeze end |
#to_formulae_and_casks(only: nil, 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.
35 36 37 38 39 40 |
# File 'Library/Homebrew/cli/named_args.rb', line 35 def to_formulae_and_casks(only: nil, method: nil) @to_formulae_and_casks ||= {} @to_formulae_and_casks[only] ||= begin to_objects(only: only, method: method).reject { |o| o.is_a?(Tap) }.freeze end end |
#to_formulae_and_casks_and_unavailable(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.
49 50 51 52 53 54 55 56 |
# File 'Library/Homebrew/cli/named_args.rb', line 49 def to_formulae_and_casks_and_unavailable(method: nil) @to_formulae_casks_unknowns ||= {} @to_formulae_casks_unknowns[method] = downcased_unique_named.map do |name| load_formula_or_cask(name, 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.
116 117 118 |
# File 'Library/Homebrew/cli/named_args.rb', line 116 def to_formulae_paths to_paths(only: :formulae) end |
#to_formulae_to_casks(method: nil, only: 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.
42 43 44 45 46 47 |
# File 'Library/Homebrew/cli/named_args.rb', line 42 def to_formulae_to_casks(method: nil, only: nil) @to_formulae_to_casks ||= {} @to_formulae_to_casks[[method, only]] = to_formulae_and_casks(method: method, only: only) .partition { |o| o.is_a?(Formula) } .map(&:freeze).freeze end |
#to_kegs ⇒ 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.
147 148 149 150 151 152 153 154 155 156 |
# File 'Library/Homebrew/cli/named_args.rb', line 147 def to_kegs @to_kegs ||= downcased_unique_named.map do |name| resolve_keg name rescue NoSuchKegError => e if (reason = Homebrew::MissingFormula.suggest_command(name, "uninstall")) $stderr.puts reason end raise e end.freeze end |
#to_kegs_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.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'Library/Homebrew/cli/named_args.rb', line 158 def to_kegs_to_casks @to_kegs_to_casks ||= begin kegs = [] casks = [] downcased_unique_named.each do |name| kegs << resolve_keg(name) warn_if_cask_conflicts(name, "keg") rescue NoSuchKegError, FormulaUnavailableError begin casks << Cask::CaskLoader.load(name, config: Cask::Config.from_args(@parent)) rescue Cask::CaskUnavailableError raise "No installed keg or cask with the name \"#{name}\"" end end [kegs.freeze, casks.freeze].freeze end end |
#to_paths(only: 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.
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.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'Library/Homebrew/cli/named_args.rb', line 123 def to_paths(only: nil) @to_paths ||= {} @to_paths[only] ||= downcased_unique_named.flat_map do |name| if File.exist?(name) Pathname(name) elsif name.count("/") == 1 Tap.fetch(name).path else next Formulary.path(name) if only == :formulae next Cask::CaskLoader.path(name) if only == :casks 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? ? name : paths end end.uniq.freeze end |
#to_resolved_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.
94 95 96 97 |
# File 'Library/Homebrew/cli/named_args.rb', line 94 def to_resolved_formulae @to_resolved_formulae ||= to_formulae_and_casks(only: :formula, method: :resolve) .freeze end |
#to_resolved_formulae_to_casks(only: 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.
99 100 101 |
# File 'Library/Homebrew/cli/named_args.rb', line 99 def to_resolved_formulae_to_casks(only: nil) to_formulae_to_casks(method: :resolve, only: only) end |