提交 c0826f18 编辑于 作者: XuehaiPan's avatar XuehaiPan
浏览文件

utils: add method `ensure_executable!`

上级 d749173a
......@@ -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("/")
......
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册