aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike McQuaid2016-12-25 23:01:40 +0000
committerMike McQuaid2016-12-29 12:51:12 +0000
commite6fb3c3114ea842884a49c7f2ddfe1a9c4e3eee0 (patch)
treeee3d418034c259627efdf58bf68bc6652aa3d109
parent59180ec370560d461d9fa44a3e510e9f1ea68375 (diff)
downloadbrew-e6fb3c3114ea842884a49c7f2ddfe1a9c4e3eee0.tar.bz2
curl: make curl_args more configurable.
Allow configuring whether output should be shown or the default the default user agent is used.
-rw-r--r--Library/Homebrew/global.rb8
-rw-r--r--Library/Homebrew/utils/curl.rb29
2 files changed, 20 insertions, 17 deletions
diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb
index eabc4c164..9a2f0c794 100644
--- a/Library/Homebrew/global.rb
+++ b/Library/Homebrew/global.rb
@@ -27,14 +27,6 @@ RUBY_BIN = RUBY_PATH.dirname
HOMEBREW_USER_AGENT_CURL = ENV["HOMEBREW_USER_AGENT_CURL"]
HOMEBREW_USER_AGENT_RUBY = "#{ENV["HOMEBREW_USER_AGENT"]} ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}".freeze
-HOMEBREW_CURL_ARGS = [
- "--fail",
- "--progress-bar",
- "--remote-time",
- "--location",
- "--user-agent", HOMEBREW_USER_AGENT_CURL
-].freeze
-
require "tap_constants"
module Homebrew
diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb
index 00c3a591c..eab623c40 100644
--- a/Library/Homebrew/utils/curl.rb
+++ b/Library/Homebrew/utils/curl.rb
@@ -1,27 +1,38 @@
require "pathname"
require "open3"
-def curl_args(extra_args = [])
+def curl_args(options = {})
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.to_s,
+ "--remote-time",
+ "--location",
+ ]
- args = [curl.to_s] + flags + extra_args
- args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"]
- args << "--silent" if !$stdout.tty? || ENV["TRAVIS"]
+ 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]
args
end
def curl(*args)
- safe_system(*curl_args(args))
+ safe_system(*curl_args(extra_args: args))
end
def curl_output(*args)
- curl_args = curl_args(args)
- curl_args -= ["--fail", "--silent"]
+ curl_args = curl_args(extra_args: args, show_output: true)
Open3.popen3(*curl_args) do |_, stdout, stderr, wait_thread|
[stdout.read, stderr.read, wait_thread.value]
end