Mike McQuaid 23306ab434 github: produce better curl error messages. (#441)
* global: add RUBY_TWO global variable.

* test-bot: use RUBY_TWO global variable.

* github: produce better curl error messages.

If we don't know why curl has failed then ensure that the error messages
that it produced are included as part of the user output.
2016-07-12 19:46:29 +01:00

35 lines
868 B
Ruby

require "pathname"
require "open3"
def curl_args(extra_args=[])
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?
flags = HOMEBREW_CURL_ARGS
flags -= ["--progress-bar"] if ARGV.verbose?
args = ["#{curl}"] + flags + extra_args
args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"]
args << "--silent" if !$stdout.tty? || ENV["TRAVIS"]
args
end
def curl(*args)
safe_system(*curl_args(args))
end
def curl_output(*args)
curl_args = curl_args(args)
curl_args -= ["--fail"]
if RUBY_TWO
curl_args -= ["--silent"]
Open3.popen3(*curl_args) do |_, stdout, stderr, wait_thread|
[stdout.read, stderr.read, wait_thread.value]
end
else
output = Utils.popen_read_text(*curl_args)
[output, nil, $?]
end
end