utils: mark reason as keyword argument in ensure_formula_installed!

This commit is contained in:
XuehaiPan 2021-11-23 23:25:32 +08:00
parent 7baaebe544
commit d749173adc
7 changed files with 13 additions and 9 deletions

View File

@ -260,7 +260,7 @@ module Homebrew
return default_tar_args return default_tar_args
end end
ensure_formula_installed!(gnu_tar, "for bottling") ensure_formula_installed!(gnu_tar, reason: "for bottling")
["#{gnu_tar.opt_bin}/gtar", gnutar_args].freeze ["#{gnu_tar.opt_bin}/gtar", gnutar_args].freeze
end end

View File

@ -59,7 +59,7 @@ module Homebrew
unless Utils::Curl.curl_supports_tls13? unless Utils::Curl.curl_supports_tls13?
begin begin
unless Pathname.new(ENV["HOMEBREW_BREWED_CURL_PATH"]).exist? unless Pathname.new(ENV["HOMEBREW_BREWED_CURL_PATH"]).exist?
ensure_formula_installed!("curl", "for Repology queries") ensure_formula_installed!("curl", reason: "for Repology queries")
end end
rescue FormulaUnavailableError rescue FormulaUnavailableError
opoo "A `curl` with TLS 1.3 support is required for Repology queries." opoo "A `curl` with TLS 1.3 support is required for Repology queries."

View File

@ -34,7 +34,7 @@ module Homebrew
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
ensure_formula_installed!( ensure_formula_installed!(
"bat", "bat",
"for displaying <formula>/<cask> source", reason: "for displaying <formula>/<cask> source",
# The user might want to capture the output of `brew cat ...` # The user might want to capture the output of `brew cat ...`
# Redirect stdout to stderr # Redirect stdout to stderr
output_to_stderr: true, output_to_stderr: true,

View File

@ -50,7 +50,7 @@ module Homebrew
with_env(HOMEBREW_NO_AUTO_UPDATE: "1", HOMEBREW_NO_BOOTSNAP: "1") do with_env(HOMEBREW_NO_AUTO_UPDATE: "1", HOMEBREW_NO_BOOTSNAP: "1") do
ensure_formula_installed!("buildpulse-test-reporter", ensure_formula_installed!("buildpulse-test-reporter",
"for reporting test flakiness") reason: "for reporting test flakiness")
end end
ENV["BUILDPULSE_ACCESS_KEY_ID"] = ENV["HOMEBREW_BUILDPULSE_ACCESS_KEY_ID"] ENV["BUILDPULSE_ACCESS_KEY_ID"] = ENV["HOMEBREW_BUILDPULSE_ACCESS_KEY_ID"]

View File

@ -53,7 +53,8 @@ class GitHubPackages
which("skopeo", ENV["HOMEBREW_PATH"]), which("skopeo", ENV["HOMEBREW_PATH"]),
HOMEBREW_PREFIX/"bin/skopeo", HOMEBREW_PREFIX/"bin/skopeo",
].compact.first ].compact.first
skopeo = ensure_formula_installed!("skopeo", "for upload").opt_bin/"skopeo" unless skopeo.exist? skopeo = ensure_formula_installed!("skopeo",
reason: "for upload").opt_bin/"skopeo" unless skopeo.exist?
require "json_schemer" require "json_schemer"

View File

@ -278,12 +278,14 @@ module Homebrew
def shellcheck def shellcheck
# Always use the latest brewed shellcheck # Always use the latest brewed shellcheck
ensure_formula_installed!("shellcheck", "for shell style checks", latest: true).opt_bin/"shellcheck" ensure_formula_installed!("shellcheck", latest: true,
reason: "for shell style checks").opt_bin/"shellcheck"
end end
def shfmt def shfmt
# Always use the latest brewed shfmt # Always use the latest brewed shfmt
ensure_formula_installed!("shfmt", "to format shell scripts", latest: true) ensure_formula_installed!("shfmt", latest: true,
reason: "to format shell scripts")
HOMEBREW_LIBRARY/"Homebrew/utils/shfmt.sh" HOMEBREW_LIBRARY/"Homebrew/utils/shfmt.sh"
end end

View File

@ -456,7 +456,7 @@ module Kernel
# Ensure the given formula is installed # Ensure the given formula is installed
# This is useful for installing a utility formula (e.g. `shellcheck` for `brew style`) # This is useful for installing a utility formula (e.g. `shellcheck` for `brew style`)
def ensure_formula_installed!(formula_or_name, reason = "", latest: false, def ensure_formula_installed!(formula_or_name, latest: false, reason: "",
output_to_stderr: true, quiet: false) output_to_stderr: true, quiet: false)
if output_to_stderr || quiet if output_to_stderr || quiet
file = if quiet file = if quiet
@ -466,7 +466,8 @@ module Kernel
end end
# Call this method itself with redirected stdout # Call this method itself with redirected stdout
redirect_stdout(file) do redirect_stdout(file) do
return ensure_formula_installed!(formula_or_name, reason, latest: latest, output_to_stderr: false) return ensure_formula_installed!(formula_or_name, latest: latest,
reason: reason, output_to_stderr: false)
end end
end end