From 9d4f37f51fb2ffdef5e318afb3cb81516dcba4f7 Mon Sep 17 00:00:00 2001 From: drbrain Date: Tue, 17 Jun 2008 22:04:18 +0000 Subject: Update RubyGems to 1.1.1 r1778 (almost 1.2) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/local_remote_options.rb | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'lib/rubygems/local_remote_options.rb') 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 -- cgit v1.2.3