2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4 # See LICENSE.txt for permissions.
11 # Mixin methods for local and remote Gem::Command options.
13 module Gem::LocalRemoteOptions
16 # Allows OptionParser to handle HTTP URIs.
19 OptionParser.accept URI::HTTP do |value|
22 rescue URI::InvalidURIError
23 raise OptionParser::InvalidArgument, value
26 raise OptionParser::InvalidArgument, value unless uri.scheme == 'http'
33 # Add local/remote options to the command line parser.
35 def add_local_remote_options
36 add_option(:"Local/Remote", '-l', '--local',
37 'Restrict operations to the LOCAL domain') do |value, options|
38 options[:domain] = :local
41 add_option(:"Local/Remote", '-r', '--remote',
42 'Restrict operations to the REMOTE domain') do |value, options|
43 options[:domain] = :remote
46 add_option(:"Local/Remote", '-b', '--both',
47 'Allow LOCAL and REMOTE operations') do |value, options|
48 options[:domain] = :both
51 add_bulk_threshold_option
54 add_update_sources_option
58 # Add the --bulk-threshold option
60 def add_bulk_threshold_option
61 add_option(:"Local/Remote", '-B', '--bulk-threshold COUNT',
62 "Threshold for switching to bulk",
63 "synchronization (default #{Gem.configuration.bulk_threshold})") do
65 Gem.configuration.bulk_threshold = value.to_i
70 # Add the --http-proxy option
75 add_option(:"Local/Remote", '-p', '--[no-]http-proxy [URL]', URI::HTTP,
76 'Use HTTP proxy for remote operations') do |value, options|
77 options[:http_proxy] = (value == false) ? :no_proxy : value
78 Gem.configuration[:http_proxy] = options[:http_proxy]
83 # Add the --source option
88 add_option(:"Local/Remote", '--source URL', URI::HTTP,
89 'Use URL as the remote source for gems') do |source, options|
90 source << '/' if source !~ /\/\z/
92 if options[:added_source] then
95 options[:added_source] = true
96 Gem.sources.replace [source]
102 # Add the --source option
104 def add_update_sources_option
106 add_option(:"Local/Remote", '-u', '--[no-]update-sources',
107 'Update local source cache') do |value, options|
108 Gem.configuration.update_sources = value
113 # Is local fetching enabled?
116 options[:domain] == :local || options[:domain] == :both
120 # Is remote fetching enabled?
123 options[:domain] == :remote || options[:domain] == :both