summaryrefslogtreecommitdiff
path: root/lib/rubygems/commands
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/commands')
-rw-r--r--lib/rubygems/commands/contents_command.rb2
-rw-r--r--lib/rubygems/commands/dependency_command.rb4
-rw-r--r--lib/rubygems/commands/environment_command.rb5
-rw-r--r--lib/rubygems/commands/fetch_command.rb10
-rw-r--r--lib/rubygems/commands/install_command.rb3
-rw-r--r--lib/rubygems/commands/query_command.rb19
-rw-r--r--lib/rubygems/commands/server_command.rb8
-rw-r--r--lib/rubygems/commands/setup_command.rb2
-rw-r--r--lib/rubygems/commands/unpack_command.rb58
-rw-r--r--lib/rubygems/commands/update_command.rb2
10 files changed, 74 insertions, 39 deletions
diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb
index ce2c655240..a49918689c 100644
--- a/lib/rubygems/commands/contents_command.rb
+++ b/lib/rubygems/commands/contents_command.rb
@@ -7,7 +7,7 @@ class Gem::Commands::ContentsCommand < Gem::Command
def initialize
super 'contents', 'Display the contents of the installed gems',
- :specdirs => [], :lib_only => false
+ :specdirs => [], :lib_only => false, :prefix => true
add_version_option
diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb
index 35702fbc6e..649e3c2d2d 100644
--- a/lib/rubygems/commands/dependency_command.rb
+++ b/lib/rubygems/commands/dependency_command.rb
@@ -159,7 +159,9 @@ class Gem::Commands::DependencyCommand < Gem::Command
response
end
- # Returns list of [specification, dep] that are satisfied by spec.
+ ##
+ # Returns an Array of [specification, dep] that are satisfied by +spec+.
+
def find_reverse_dependencies(spec)
result = []
diff --git a/lib/rubygems/commands/environment_command.rb b/lib/rubygems/commands/environment_command.rb
index f3550cae28..a8284b4bf6 100644
--- a/lib/rubygems/commands/environment_command.rb
+++ b/lib/rubygems/commands/environment_command.rb
@@ -69,7 +69,7 @@ lib/rubygems/defaults/operating_system.rb
when /^packageversion/ then
out << Gem::RubyGemsPackageVersion
when /^version/ then
- out << Gem::RubyGemsVersion
+ out << Gem::VERSION
when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then
out << Gem.dir
when /^gempath/, /^path/, /^GEM_PATH/ then
@@ -79,7 +79,7 @@ lib/rubygems/defaults/operating_system.rb
when nil then
out = "RubyGems Environment:\n"
- out << " - RUBYGEMS VERSION: #{Gem::RubyGemsVersion}\n"
+ out << " - RUBYGEMS VERSION: #{Gem::VERSION}\n"
out << " - RUBY VERSION: #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
out << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
@@ -109,6 +109,7 @@ lib/rubygems/defaults/operating_system.rb
out << " - GEM CONFIGURATION:\n"
Gem.configuration.each do |name, value|
+ value = value.gsub(/./, '*') if name == 'gemcutter_key'
out << " - #{name.inspect} => #{value.inspect}\n"
end
diff --git a/lib/rubygems/commands/fetch_command.rb b/lib/rubygems/commands/fetch_command.rb
index b12e1b4a5d..43229c0512 100644
--- a/lib/rubygems/commands/fetch_command.rb
+++ b/lib/rubygems/commands/fetch_command.rb
@@ -34,7 +34,7 @@ class Gem::Commands::FetchCommand < Gem::Command
def execute
version = options[:version] || Gem::Requirement.default
- all = Gem::Requirement.default
+ all = Gem::Requirement.default != version
gem_names = get_all_gem_names
@@ -42,13 +42,17 @@ class Gem::Commands::FetchCommand < Gem::Command
dep = Gem::Dependency.new gem_name, version
dep.prerelease = options[:prerelease]
- specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, false, true,
+ specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, all, true,
dep.prerelease?)
+ specs_and_sources, errors =
+ Gem::SpecFetcher.fetcher.fetch_with_errors(dep, all, true,
+ dep.prerelease?)
+
spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last
if spec.nil? then
- alert_error "Could not find #{gem_name} in any repository"
+ show_lookup_failure gem_name, version, errors
next
end
diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb
index df6b3e5f2c..06a89eeb0a 100644
--- a/lib/rubygems/commands/install_command.rb
+++ b/lib/rubygems/commands/install_command.rb
@@ -127,7 +127,8 @@ to write the specification by hand. For example:
alert_error "Error installing #{gem_name}:\n\t#{e.message}"
exit_code |= 1
rescue Gem::GemNotFoundException => e
- alert_error e.message
+ show_lookup_failure e.name, e.version, e.errors
+
exit_code |= 2
end
end
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb
index 7dd0a4a0d6..93b417015c 100644
--- a/lib/rubygems/commands/query_command.rb
+++ b/lib/rubygems/commands/query_command.rb
@@ -21,7 +21,7 @@ class Gem::Commands::QueryCommand < Gem::Command
options[:installed] = value
end
- add_version_option
+ add_version_option command, "for use with --installed"
add_option('-n', '--name-matches REGEXP',
'Name of gem(s) to query on matches the',
@@ -185,8 +185,21 @@ class Gem::Commands::QueryCommand < Gem::Command
entry = gem_name.dup
if options[:versions] then
- versions = matching_tuples.map { |(name, version,_),_| version }.uniq
- entry << " (#{versions.join ', '})"
+ list = if platforms.empty? or options[:details] then
+ matching_tuples.map { |(name, version,_),_| version }.uniq
+ else
+ platforms.sort.reverse.map do |version, pls|
+ if pls == [Gem::Platform::RUBY] then
+ version
+ else
+ ruby = pls.delete Gem::Platform::RUBY
+ platform_list = [ruby, *pls.sort].compact
+ "#{version} #{platform_list.join ' '}"
+ end
+ end
+ end.join ', '
+
+ entry << " (#{list})"
end
if options[:details] then
diff --git a/lib/rubygems/commands/server_command.rb b/lib/rubygems/commands/server_command.rb
index 6bc58367e9..4277787035 100644
--- a/lib/rubygems/commands/server_command.rb
+++ b/lib/rubygems/commands/server_command.rb
@@ -5,7 +5,7 @@ class Gem::Commands::ServerCommand < Gem::Command
def initialize
super 'server', 'Documentation and gem repository HTTP server',
- :port => 8808, :gemdir => Gem.dir, :daemon => false
+ :port => 8808, :gemdir => [], :daemon => false
OptionParser.accept :Port do |port|
if port =~ /\A\d+\z/ then
@@ -29,8 +29,9 @@ class Gem::Commands::ServerCommand < Gem::Command
end
add_option '-d', '--dir=GEMDIR',
- 'directory from which to serve gems' do |gemdir, options|
- options[:gemdir] = File.expand_path gemdir
+ 'directories from which to serve gems',
+ 'multiple directories may be provided' do |gemdir, options|
+ options[:gemdir] << File.expand_path(gemdir)
end
add_option '--[no-]daemon', 'run as a daemon' do |daemon, options|
@@ -69,6 +70,7 @@ You can set up a shortcut to gem server documentation using the URL:
end
def execute
+ options[:gemdir] << Gem.dir if options[:gemdir].empty?
Gem::Server.run options
end
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index f5f5185f86..4bc115eaf8 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -231,7 +231,7 @@ TEXT
def install_rdoc
gem_doc_dir = File.join Gem.dir, 'doc'
- rubygems_name = "rubygems-#{Gem::RubyGemsVersion}"
+ rubygems_name = "rubygems-#{Gem::VERSION}"
rubygems_doc_dir = File.join gem_doc_dir, rubygems_name
if File.writable? gem_doc_dir and
diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb
index 84a53b107a..8ed99babbe 100644
--- a/lib/rubygems/commands/unpack_command.rb
+++ b/lib/rubygems/commands/unpack_command.rb
@@ -12,7 +12,8 @@ class Gem::Commands::UnpackCommand < Gem::Command
:version => Gem::Requirement.default,
:target => Dir.pwd
- add_option('--target=DIR', 'target directory for unpacking') do |value, options|
+ add_option('--target=DIR',
+ 'target directory for unpacking') do |value, options|
options[:target] = value
end
@@ -31,6 +32,16 @@ class Gem::Commands::UnpackCommand < Gem::Command
"#{program_name} GEMNAME"
end
+ def download dependency
+ found = Gem::SpecFetcher.fetcher.fetch dependency
+
+ return if found.empty?
+
+ spec, source_uri = found.first
+
+ Gem::RemoteFetcher.fetcher.download spec, source_uri
+ end
+
#--
# TODO: allow, e.g., 'gem unpack rake-0.3.1'. Find a general solution for
# this, so that it works for uninstall as well. (And check other commands
@@ -38,11 +49,12 @@ class Gem::Commands::UnpackCommand < Gem::Command
def execute
get_all_gem_names.each do |name|
- path = get_path name, options[:version]
+ dependency = Gem::Dependency.new name, options[:version]
+ path = get_path dependency
if path then
- basename = File.basename(path, '.gem')
- target_dir = File.expand_path File.join(options[:target], basename)
+ basename = File.basename path, '.gem'
+ target_dir = File.expand_path basename, options[:target]
FileUtils.mkdir_p target_dir
Gem::Installer.new(path, :unpack => true).unpack target_dir
say "Unpacked gem: '#{target_dir}'"
@@ -52,14 +64,15 @@ class Gem::Commands::UnpackCommand < Gem::Command
end
end
+ ##
# Return the full path to the cached gem file matching the given
# name and version requirement. Returns 'nil' if no match.
#
# Example:
#
- # get_path('rake', '> 0.4') # -> '/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem'
- # get_path('rake', '< 0.1') # -> nil
- # get_path('rak') # -> nil (exact name required)
+ # get_path 'rake', '> 0.4' # "/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem"
+ # get_path 'rake', '< 0.1' # nil
+ # get_path 'rak' # nil (exact name required)
#--
# TODO: This should be refactored so that it's a general service. I don't
# think any of our existing classes are the right place though. Just maybe
@@ -67,30 +80,29 @@ class Gem::Commands::UnpackCommand < Gem::Command
#
# TODO: It just uses Gem.dir for now. What's an easy way to get the list of
# source directories?
- def get_path(gemname, version_req)
- return gemname if gemname =~ /\.gem$/i
- specs = Gem::source_index.find_name gemname, version_req
+ def get_path dependency
+ return dependency.name if dependency.name =~ /\.gem$/i
+
+ specs = Gem.source_index.search dependency
selected = specs.sort_by { |s| s.version }.last
- return nil if selected.nil?
+ return download(dependency) if selected.nil?
- # We expect to find (basename).gem in the 'cache' directory.
- # Furthermore, the name match must be exact (ignoring case).
- if gemname =~ /^#{selected.name}$/i
- filename = selected.file_name
- path = nil
+ return unless dependency.name =~ /^#{selected.name}$/i
- Gem.path.find do |gem_dir|
- path = File.join gem_dir, 'cache', filename
- File.exist? path
- end
+ # We expect to find (basename).gem in the 'cache' directory. Furthermore,
+ # the name match must be exact (ignoring case).
+ filename = selected.file_name
+ path = nil
- path
- else
- nil
+ Gem.path.find do |gem_dir|
+ path = File.join gem_dir, 'cache', filename
+ File.exist? path
end
+
+ path
end
end
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb
index 4b0439df1f..45d82e9385 100644
--- a/lib/rubygems/commands/update_command.rb
+++ b/lib/rubygems/commands/update_command.rb
@@ -56,7 +56,7 @@ class Gem::Commands::UpdateCommand < Gem::Command
rubygems_update = Gem::Specification.new
rubygems_update.name = 'rubygems-update'
- rubygems_update.version = Gem::Version.new Gem::RubyGemsVersion
+ rubygems_update.version = Gem::Version.new Gem::VERSION
hig['rubygems-update'] = rubygems_update
options[:user_install] = false