47 lines
1.0 KiB
Ruby
Raw Normal View History

require "pathname"
require "open3"
2017-08-04 16:24:29 +02:00
def curl_executable
curl = Pathname.new ENV["HOMEBREW_CURL"]
curl = Pathname.new "/usr/bin/curl" unless curl.exist?
2017-08-04 16:24:29 +02:00
return curl if curl.executable?
raise "#{curl} is not executable"
end
2017-08-04 16:24:29 +02:00
def curl_args(*extra_args, show_output: false, user_agent: :default)
args = [
2017-08-04 16:24:29 +02:00
curl_executable.to_s,
"--fail",
"--show-error",
]
2017-08-04 16:24:29 +02:00
args << "--user-agent" << case user_agent
when :browser, :fake
HOMEBREW_USER_AGENT_FAKE_SAFARI
when :default
HOMEBREW_USER_AGENT_CURL
else
2017-08-04 16:24:29 +02:00
user_agent
end
2017-08-04 16:24:29 +02:00
unless show_output
args << "--progress-bar" unless ARGV.verbose?
args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"]
args << "--silent" if !$stdout.tty? || ENV["TRAVIS"]
end
2017-08-04 16:24:29 +02:00
args + extra_args
end
def curl(*args)
2017-08-04 16:24:29 +02:00
safe_system(*curl_args(*args))
end
2017-08-04 16:24:29 +02:00
def curl_download(*args, to: nil, **options)
curl(*args, "--location", "--remote-time", "--continue-at", "-", "--output", to, **options)
end
def curl_output(*args, **options)
Open3.capture3(*curl_args(*args, show_output: true, **options))
end