2016-06-03 13:05:18 +01:00
|
|
|
require "pathname"
|
2016-07-12 19:46:29 +01:00
|
|
|
require "open3"
|
2016-06-03 13:05:18 +01:00
|
|
|
|
2016-12-25 23:01:40 +00:00
|
|
|
def curl_args(options = {})
|
2016-06-03 13:05:18 +01:00
|
|
|
curl = Pathname.new ENV["HOMEBREW_CURL"]
|
|
|
|
curl = Pathname.new "/usr/bin/curl" unless curl.exist?
|
|
|
|
raise "#{curl} is not executable" unless curl.exist? && curl.executable?
|
|
|
|
|
2016-12-25 23:01:40 +00:00
|
|
|
args = [
|
|
|
|
curl.to_s,
|
|
|
|
"--remote-time",
|
|
|
|
"--location",
|
|
|
|
]
|
2016-06-03 13:05:18 +01:00
|
|
|
|
2016-12-25 23:01:40 +00:00
|
|
|
unless options[:default_user_agent]
|
|
|
|
args << "--user-agent" << HOMEBREW_USER_AGENT_CURL
|
|
|
|
end
|
|
|
|
|
|
|
|
unless options[:show_output]
|
|
|
|
args << "--progress-bar" unless ARGV.verbose?
|
|
|
|
args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"]
|
|
|
|
args << "--fail"
|
|
|
|
args << "--silent" if !$stdout.tty? || ENV["TRAVIS"]
|
|
|
|
end
|
|
|
|
|
|
|
|
args += options[:extra_args] if options[:extra_args]
|
2016-06-03 13:05:18 +01:00
|
|
|
args
|
|
|
|
end
|
|
|
|
|
|
|
|
def curl(*args)
|
2016-12-25 23:01:40 +00:00
|
|
|
safe_system(*curl_args(extra_args: args))
|
2016-06-03 13:05:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def curl_output(*args)
|
2016-12-25 23:01:40 +00:00
|
|
|
curl_args = curl_args(extra_args: args, show_output: true)
|
2016-08-16 17:00:38 +01:00
|
|
|
Open3.popen3(*curl_args) do |_, stdout, stderr, wait_thread|
|
|
|
|
[stdout.read, stderr.read, wait_thread.value]
|
2016-07-12 19:46:29 +01:00
|
|
|
end
|
2016-06-03 13:05:18 +01:00
|
|
|
end
|