Class: Homebrew::Cmd::UpgradeCmd Private

Inherits:
AbstractCommand show all
Defined in:
cmd/upgrade.rb,
sorbet/rbi/dsl/homebrew/cmd/upgrade_cmd.rbi

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.

Defined Under Namespace

Classes: Args, FormulaeUpgradeContext

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::Cmd::UpgradeCmd::Args

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.



10
# File 'sorbet/rbi/dsl/homebrew/cmd/upgrade_cmd.rbi', line 10

def args; end

#runvoid

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.

This method returns an undefined value.



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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'cmd/upgrade.rb', line 134

def run
  if args.build_from_source? && args.named.empty?
    raise ArgumentError, "`--build-from-source` requires at least one formula"
  end

  formulae = T.let([], T::Array[Formula])
  casks = T.let([], T::Array[Cask::Cask])
  unavailable_errors = T.let(
    [],
    T::Array[T.any(FormulaOrCaskUnavailableError, NoSuchKegError)],
  )
  @prefetched_formulae_upgrade_context = T.let(nil, T.nilable(FormulaeUpgradeContext))
  prefetched_formulae_names = T.let([], T::Array[String])
  prefetched_cask_names = T.let([], T::Array[String])

  if args.named.present?
    args.named.to_formulae_and_casks_and_unavailable(method: :resolve).each do |item|
      case item
      when FormulaOrCaskUnavailableError, NoSuchKegError
        unavailable_errors << item
      when Formula
        formulae << item
      when Cask::Cask
        casks << item
      end
    end
  end

  # If one or more formulae are specified, but no casks were
  # specified, we want to make note of that so we don't
  # try to upgrade all outdated casks.
  #
  # When names were given, we must also prevent empty resolved lists
  # from triggering the "upgrade all" path (which happens when all
  # names failed resolution).
  named_given = args.named.present?
  only_upgrade_formulae = (named_given && casks.blank?) || (formulae.present? && casks.blank?)
  only_upgrade_casks = (named_given && formulae.blank?) || (casks.present? && formulae.blank?)

  formulae = Homebrew::Attestation.sort_formulae_for_install(formulae) if Homebrew::Attestation.enabled?

  prefetched_casks = T.let(false, T::Boolean)
  shared_download_queue = T.let(nil, T.nilable(Homebrew::DownloadQueue))
  if !args.dry_run? && !only_upgrade_formulae && !only_upgrade_casks
    shared_download_queue = Homebrew::DownloadQueue.new(pour: true)
    begin
      upgrade_outdated_formulae!(
        formulae,
        prefetch_only:          true,
        download_queue:         shared_download_queue,
        prefetch_names:         prefetched_formulae_names,
        show_downloads_heading: false,
      )
      prefetched_casks = prefetch_outdated_casks!(
        casks,
        download_queue:         shared_download_queue,
        prefetch_names:         prefetched_cask_names,
        show_downloads_heading: false,
      )
      Install.show_combined_fetch_downloads_heading(
        formula_names: prefetched_formulae_names,
        cask_names:    prefetched_cask_names,
      )
      shared_download_queue.fetch
    ensure
      shared_download_queue.shutdown
    end
  end

  upgrade_outdated_formulae!(formulae, use_prefetched: true) unless only_upgrade_casks
  unless only_upgrade_formulae
    upgrade_outdated_casks!(
      casks,
      skip_prefetch:  prefetched_casks,
      download_queue: nil,
    )
  end

  unavailable_errors.each { |e| ofail e }

  Cleanup.periodic_clean!(dry_run: args.dry_run?)

  Homebrew::Reinstall.reinstall_pkgconf_if_needed!(dry_run: args.dry_run?)

  Homebrew.messages.display_messages(display_times: args.display_times?)
end