diff options
-rw-r--r-- | lib/rubygems/commands/query_command.rb | 73 |
1 files changed, 52 insertions, 21 deletions
@@ -2,9 +2,11 @@ require 'rubygems/command' require 'rubygems/local_remote_options' require 'rubygems/spec_fetcher' require 'rubygems/version_option' class Gem::Commands::QueryCommand < Gem::Command include Gem::LocalRemoteOptions include Gem::VersionOption @@ -43,6 +45,11 @@ class Gem::Commands::QueryCommand < Gem::Command options[:all] = value end add_local_remote_options end @@ -54,6 +61,7 @@ class Gem::Commands::QueryCommand < Gem::Command exit_code = 0 name = options[:name] 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 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 rescue Gem::RemoteFetcher::FetchError => e 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 seen = {} matching_tuples.delete_if do |(name, version,_),_| @@ -174,6 +197,28 @@ class Gem::Commands::QueryCommand < Gem::Command end entry << "\n" 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.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 |