diff options
Diffstat (limited to 'lib/rubygems/local_remote_options.rb')
-rw-r--r-- | lib/rubygems/local_remote_options.rb | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/rubygems/local_remote_options.rb b/lib/rubygems/local_remote_options.rb index 1a5410bef7..799b9d5893 100644 --- a/lib/rubygems/local_remote_options.rb +++ b/lib/rubygems/local_remote_options.rb @@ -4,27 +4,34 @@ # See LICENSE.txt for permissions. #++ +require 'uri' require 'rubygems' +## # Mixin methods for local and remote Gem::Command options. + module Gem::LocalRemoteOptions + ## # Allows OptionParser to handle HTTP URIs. + def accept_uri_http OptionParser.accept URI::HTTP do |value| begin - value = URI.parse value + uri = URI.parse value rescue URI::InvalidURIError raise OptionParser::InvalidArgument, value end - raise OptionParser::InvalidArgument, value unless value.scheme == 'http' + raise OptionParser::InvalidArgument, value unless uri.scheme == 'http' value end end + ## # Add local/remote options to the command line parser. + def add_local_remote_options add_option(:"Local/Remote", '-l', '--local', 'Restrict operations to the LOCAL domain') do |value, options| @@ -47,7 +54,9 @@ module Gem::LocalRemoteOptions add_update_sources_option end + ## # Add the --bulk-threshold option + def add_bulk_threshold_option add_option(:"Local/Remote", '-B', '--bulk-threshold COUNT', "Threshold for switching to bulk", @@ -57,7 +66,9 @@ module Gem::LocalRemoteOptions end end + ## # Add the --http-proxy option + def add_proxy_option accept_uri_http @@ -68,22 +79,28 @@ module Gem::LocalRemoteOptions end end + ## # Add the --source option + def add_source_option accept_uri_http add_option(:"Local/Remote", '--source URL', URI::HTTP, - 'Use URL as the remote source for gems') do |value, options| + 'Use URL as the remote source for gems') do |source, options| + source << '/' if source !~ /\/\z/ + if options[:added_source] then - Gem.sources << value + Gem.sources << source else options[:added_source] = true - Gem.sources.replace [value] + Gem.sources.replace [source] end end end + ## # Add the --source option + def add_update_sources_option add_option(:"Local/Remote", '-u', '--[no-]update-sources', @@ -92,12 +109,16 @@ module Gem::LocalRemoteOptions end end + ## # Is local fetching enabled? + def local? options[:domain] == :local || options[:domain] == :both end + ## # Is remote fetching enabled? + def remote? options[:domain] == :remote || options[:domain] == :both end |