diff options
Diffstat (limited to 'lib/rubygems/commands/fetch_command.rb')
-rw-r--r-- | lib/rubygems/commands/fetch_command.rb | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/rubygems/commands/fetch_command.rb b/lib/rubygems/commands/fetch_command.rb index 373851643d..c8ecb0d48c 100644 --- a/lib/rubygems/commands/fetch_command.rb +++ b/lib/rubygems/commands/fetch_command.rb @@ -8,7 +8,12 @@ class Gem::Commands::FetchCommand < Gem::Command include Gem::VersionOption def initialize - super 'fetch', 'Download a gem and place it in the current directory' + defaults = { + :suggest_alternate => true, + :version => Gem::Requirement.default, + } + + super 'fetch', 'Download a gem and place it in the current directory', defaults add_bulk_threshold_option add_proxy_option @@ -18,6 +23,10 @@ class Gem::Commands::FetchCommand < Gem::Command add_version_option add_platform_option add_prerelease_option + + add_option '--[no-]suggestions', 'Suggest alternates when gems are not found' do |value, options| + options[:suggest_alternate] = value + end end def arguments # :nodoc: @@ -42,15 +51,27 @@ then repackaging it. "#{program_name} GEMNAME [GEMNAME ...]" end + def check_version # :nodoc: + if options[:version] != Gem::Requirement.default and + get_all_gem_names.size > 1 + alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ + " version requirements using `gem fetch 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" + terminate_interaction 1 + end + end + def execute - version = options[:version] || Gem::Requirement.default + check_version + version = options[:version] platform = Gem.platforms.last - gem_names = get_all_gem_names + gem_names = get_all_gem_names_and_versions - gem_names.each do |gem_name| - dep = Gem::Dependency.new gem_name, version + gem_names.each do |gem_name, gem_version| + gem_version ||= version + dep = Gem::Dependency.new gem_name, gem_version dep.prerelease = options[:prerelease] + suppress_suggestions = !options[:suggest_alternate] specs_and_sources, errors = Gem::SpecFetcher.fetcher.spec_for_dependency dep @@ -63,12 +84,10 @@ then repackaging it. spec, source = specs_and_sources.max_by {|s,| s } if spec.nil? - show_lookup_failure gem_name, version, errors, options[:domain] + show_lookup_failure gem_name, gem_version, errors, suppress_suggestions, options[:domain] next end - source.download spec - say "Downloaded #{spec.full_name}" end end |