Class: Homebrew::CLI::NamedArgs Private

Inherits:
Array
  • Object
show all
Defined in:
cli/named_args.rb

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

Instance Method Summary collapse

Constructor Details

#initialize(*args, parent: Args.new, override_spec: nil, force_bottle: false, flags: [], cask_options: false) ⇒ NamedArgs

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 a new instance of NamedArgs.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'cli/named_args.rb', line 16

def initialize(*args, parent: Args.new, override_spec: nil, force_bottle: false, flags: [], cask_options: 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 = cask_options
  @parent = parent

  super(@args)
end

Instance Attribute Details

#parentObject (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.



33
34
35
# File 'cli/named_args.rb', line 33

def parent
  @parent
end

Instance Method Details

#homebrew_tap_cask_namesArray<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.

Returns:



291
292
293
# File 'cli/named_args.rb', line 291

def homebrew_tap_cask_names
  downcased_unique_named.grep(HOMEBREW_CASK_TAP_CASK_REGEX)
end

#to_casksObject

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.



35
36
37
# File 'cli/named_args.rb', line 35

def to_casks
  @to_casks ||= to_formulae_and_casks(only: :cask).freeze
end

#to_default_kegsArray<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.

Returns:



230
231
232
233
234
235
236
237
238
239
# File 'cli/named_args.rb', line 230

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_formulaeObject

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.



39
40
41
# File 'cli/named_args.rb', line 39

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, uniq: true) ⇒ 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.

Parameters:

  • only (Symbol, nil) (defaults to: parent&.only_formula_or_cask)
  • ignore_unavailable (Boolean, nil) (defaults to: nil)
  • method (Symbol, nil) (defaults to: nil)
  • uniq (Boolean) (defaults to: true)

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'cli/named_args.rb', line 54

def to_formulae_and_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, method: nil, uniq: true)
  @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 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.



82
83
84
85
86
87
88
89
# File 'cli/named_args.rb', line 82

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_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.



75
76
77
78
79
80
# File 'cli/named_args.rb', line 75

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) || o.is_a?(Keg) }
                                          .map(&:freeze).freeze
end

#to_installed_tapsArray<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.

Returns:



284
285
286
287
288
# File 'cli/named_args.rb', line 284

def to_installed_taps
  @to_installed_taps ||= to_taps.each do |tap|
    raise TapUnavailableError, tap.name unless tap.installed?
  end.uniq.freeze
end

#to_kegsArray<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.

Returns:



254
255
256
257
258
259
260
261
262
263
# File 'cli/named_args.rb', line 254

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.

Parameters:

  • only (Symbol, nil) (defaults to: parent&.only_formula_or_cask)
  • ignore_unavailable (Boolean, nil) (defaults to: nil)
  • all_kegs (Boolean, nil) (defaults to: nil)

Returns:



269
270
271
272
273
274
275
276
# File 'cli/named_args.rb', line 269

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: only, ignore_unavailable: ignore_unavailable, method: method)
    .partition { |o| o.is_a?(Keg) }
    .map(&:freeze).freeze
end

#to_latest_kegsArray<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.

Returns:



242
243
244
245
246
247
248
249
250
251
# File 'cli/named_args.rb', line 242

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.

Parameters:

  • only (Symbol, nil) (defaults to: parent&.only_formula_or_cask)
  • recurse_tap (Boolean) (defaults to: false)

Returns:



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
# File 'cli/named_args.rb', line 198

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(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.

Parameters:

  • uniq (Boolean) (defaults to: true)

Returns:



185
186
187
188
# File 'cli/named_args.rb', line 185

def to_resolved_formulae(uniq: true)
  @to_resolved_formulae ||= to_formulae_and_casks(only: :formula, method: :resolve, uniq: 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.



190
191
192
# File 'cli/named_args.rb', line 190

def to_resolved_formulae_to_casks(only: parent&.only_formula_or_cask)
  to_formulae_to_casks(only: only, method: :resolve)
end

#to_tapsArray<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.

Returns:



279
280
281
# File 'cli/named_args.rb', line 279

def to_taps
  @to_taps ||= downcased_unique_named.map { |name| Tap.fetch name }.uniq.freeze
end