Module: Homebrew::Bundle::Installer Private

Defined in:
bundle/installer.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: InstallableEntry

Class Method Summary collapse

Class Method Details

.fetchable_formulae_and_casks(entries, no_upgrade:) ⇒ 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.

Parameters:

Returns:



101
102
103
104
105
# File 'bundle/installer.rb', line 101

def self.fetchable_formulae_and_casks(entries, no_upgrade:)
  entries.filter_map do |entry|
    entry.cls.fetchable_name(entry.name, entry.options, no_upgrade:)
  end
end

.install!(entries, global: false, file: nil, no_lock: false, no_upgrade: false, verbose: false, force: false, quiet: false) ⇒ Boolean

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:

  • entries (Array<Dsl::Entry>)
  • global (Boolean) (defaults to: false)
  • file (String, nil) (defaults to: nil)
  • no_lock (Boolean) (defaults to: false)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • force (Boolean) (defaults to: false)
  • quiet (Boolean) (defaults to: false)

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'bundle/installer.rb', line 30

def self.install!(entries, global: false, file: nil, no_lock: false, no_upgrade: false, verbose: false,
                  force: false, quiet: false)
  success = 0
  failure = 0

  installable_entries = entries.filter_map do |entry|
    next if Homebrew::Bundle::Skipper.skip? entry

    name = entry.name
    options = entry.options
    type = entry.type
    cls = Homebrew::Bundle.installable(type)
    next if cls.nil? || !cls.install_supported?

    InstallableEntry.new(name:, options:, verb: cls.install_verb(name, options), cls:)
  end

  if (fetchable_names = fetchable_formulae_and_casks(installable_entries, no_upgrade:).presence)
    fetchable_names_joined = fetchable_names.join(", ")
    puts Formatter.success("Fetching #{fetchable_names_joined}") unless quiet
    unless Bundle.brew("fetch", *fetchable_names, verbose:)
      $stderr.puts Formatter.error "`brew bundle` failed! Failed to fetch #{fetchable_names_joined}"
      return false
    end
  end

  installable_entries.each do |entry|
    name = entry.name
    options = entry.options
    verb = entry.verb
    cls = entry.cls

    preinstall = if cls.preinstall!(name, **options, no_upgrade:, verbose:)
      puts Formatter.success("#{verb} #{name}")
      true
    else
      puts "Using #{name}" unless quiet
      false
    end

    if cls.install!(name, **options,
                   preinstall:, no_upgrade:, verbose:, force:)
      success += 1
    else
      $stderr.puts Formatter.error("#{verb} #{name} has failed!")
      failure += 1
    end
  end

  unless failure.zero?
    require "utils"
    dependency = Utils.pluralize("dependency", failure)
    $stderr.puts Formatter.error "`brew bundle` failed! #{failure} Brewfile #{dependency} failed to install"
    return false
  end

  unless quiet
    require "utils"
    dependency = Utils.pluralize("dependency", success)
    puts Formatter.success "`brew bundle` complete! #{success} Brewfile #{dependency} now installed."
  end

  true
end