diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-09 21:38:59 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-09 21:38:59 +0000 |
commit | 31c94ffeb5f09d09ac2c86fc9e6614e38251a43d (patch) | |
tree | 10e44506238c7af3d7c9d822111996731726e38d /lib/rubygems/commands/query_command.rb | |
parent | a6afbaeb3be396c0fdea3b9077d9256c59edcfca (diff) | |
download | ruby-31c94ffeb5f09d09ac2c86fc9e6614e38251a43d.tar.gz |
Update to RubyGems 1.3.4 r2223
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/commands/query_command.rb')
-rw-r--r-- | lib/rubygems/commands/query_command.rb | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb index 29fe8acb79..88f7f0b54e 100644 --- a/lib/rubygems/commands/query_command.rb +++ b/lib/rubygems/commands/query_command.rb @@ -2,9 +2,11 @@ require 'rubygems/command' require 'rubygems/local_remote_options' require 'rubygems/spec_fetcher' require 'rubygems/version_option' +require 'rubygems/text' class Gem::Commands::QueryCommand < Gem::Command + include Gem::Text include Gem::LocalRemoteOptions include Gem::VersionOption @@ -43,6 +45,11 @@ class Gem::Commands::QueryCommand < Gem::Command options[:all] = value end + add_option( '--prerelease', + 'Display prerelease versions') do |value, options| + options[:prerelease] = value + end + add_local_remote_options end @@ -54,6 +61,7 @@ class Gem::Commands::QueryCommand < Gem::Command exit_code = 0 name = options[:name] + prerelease = options[:prerelease] if options[:installed] then if name.source.empty? then @@ -72,6 +80,10 @@ class Gem::Commands::QueryCommand < Gem::Command dep = Gem::Dependency.new name, Gem::Requirement.default if local? then + if prerelease and not both? then + alert_warning "prereleases are always shown locally" + end + if ui.outs.tty? or both? then say say "*** LOCAL GEMS ***" @@ -98,8 +110,13 @@ class Gem::Commands::QueryCommand < Gem::Command begin fetcher = Gem::SpecFetcher.fetcher - spec_tuples = fetcher.find_matching dep, all, false + spec_tuples = fetcher.find_matching dep, all, false, prerelease rescue Gem::RemoteFetcher::FetchError => e + if prerelease then + raise Gem::OperationNotSupportedError, + "Prereleases not supported on legacy repositories" + end + raise unless fetcher.warn_legacy e do require 'rubygems/source_info_cache' @@ -145,6 +162,12 @@ class Gem::Commands::QueryCommand < Gem::Command version end.reverse + platforms = Hash.new { |h,version| h[version] = [] } + + matching_tuples.map do |(name, version, platform,_),_| + platforms[version] << platform if platform + end + seen = {} matching_tuples.delete_if do |(name, version,_),_| @@ -174,6 +197,28 @@ class Gem::Commands::QueryCommand < Gem::Command end entry << "\n" + + non_ruby = platforms.any? do |_, pls| + pls.any? { |pl| pl != Gem::Platform::RUBY } + end + + if non_ruby then + if platforms.length == 1 then + title = platforms.values.length == 1 ? 'Platform' : 'Platforms' + entry << " #{title}: #{platforms.values.sort.join ', '}\n" + else + entry << " Platforms:\n" + platforms.sort_by do |version,| + version + end.each do |version, pls| + label = " #{version}: " + data = format_text pls.sort.join(', '), 68, label.length + data[0, label.length] = label + entry << data << "\n" + end + end + end + authors = "Author#{spec.authors.length > 1 ? 's' : ''}: " authors << spec.authors.join(', ') entry << format_text(authors, 68, 4) @@ -187,6 +232,12 @@ class Gem::Commands::QueryCommand < Gem::Command entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4) end + if spec.license and not spec.license.empty? then + licenses = "License#{spec.licenses.length > 1 ? 's' : ''}: " + licenses << spec.licenses.join(', ') + entry << "\n" << format_text(licenses, 68, 4) + end + if spec.loaded_from then if matching_tuples.length == 1 then loaded_from = File.dirname File.dirname(spec.loaded_from) @@ -209,25 +260,5 @@ class Gem::Commands::QueryCommand < Gem::Command say output.join(options[:details] ? "\n\n" : "\n") end - ## - # Used for wrapping and indenting text - - def format_text(text, wrap, indent=0) - result = [] - work = text.dup - - while work.length > wrap - if work =~ /^(.{0,#{wrap}})[ \n]/o then - result << $1 - work.slice!(0, $&.length) - else - result << work.slice!(0, wrap) - end - end - - result << work if work.length.nonzero? - result.join("\n").gsub(/^/, " " * indent) - end - end |