utils: add method ensure_executable!
This commit is contained in:
parent
d749173adc
commit
c0826f1890
@ -48,13 +48,7 @@ class GitHubPackages
|
||||
raise UsageError, "HOMEBREW_GITHUB_PACKAGES_USER is unset." if user.blank?
|
||||
raise UsageError, "HOMEBREW_GITHUB_PACKAGES_TOKEN is unset." if token.blank?
|
||||
|
||||
skopeo = [
|
||||
which("skopeo"),
|
||||
which("skopeo", ENV["HOMEBREW_PATH"]),
|
||||
HOMEBREW_PREFIX/"bin/skopeo",
|
||||
].compact.first
|
||||
skopeo = ensure_formula_installed!("skopeo",
|
||||
reason: "for upload").opt_bin/"skopeo" unless skopeo.exist?
|
||||
skopeo = ensure_executable!("skopeo", reason: "for upload")
|
||||
|
||||
require "json_schemer"
|
||||
|
||||
|
||||
@ -494,6 +494,20 @@ module Kernel
|
||||
formula
|
||||
end
|
||||
|
||||
# Ensure the given executable is exist otherwise install the brewed version
|
||||
def ensure_executable!(name, formula_name = nil, reason: "")
|
||||
formula_name ||= name
|
||||
|
||||
executable = [
|
||||
which(name),
|
||||
which(name, ENV["HOMEBREW_PATH"]),
|
||||
HOMEBREW_PREFIX/"bin/#{name}",
|
||||
].compact.first
|
||||
return executable if executable.exist?
|
||||
|
||||
ensure_formula_installed!(formula_name, reason: reason).opt_bin/name
|
||||
end
|
||||
|
||||
def paths
|
||||
@paths ||= PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
|
||||
File.expand_path(p).chomp("/")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user