summaryrefslogtreecommitdiff
path: root/lib/rubygems/commands/query_command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/commands/query_command.rb')
-rw-r--r--lib/rubygems/commands/query_command.rb46
1 files changed, 31 insertions, 15 deletions
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb
index c9c30149754..55b950c1b7c 100644
--- a/lib/rubygems/commands/query_command.rb
+++ b/lib/rubygems/commands/query_command.rb
@@ -72,16 +72,26 @@ is too hard to use.
def execute
exit_code = 0
+ if options[:args].to_a.empty? and options[:name].source.empty?
+ name = options[:name]
+ no_name = true
+ elsif !options[:name].source.empty?
+ name = Array(options[:name])
+ else
+ name = options[:args].to_a.map{|arg| /#{arg}/i }
+ end
- name = options[:name]
prerelease = options[:prerelease]
unless options[:installed].nil? then
- if name.source.empty? then
+ if no_name then
alert_error "You must specify a gem name"
exit_code |= 4
+ elsif name.count > 1
+ alert_error "You must specify only ONE gem!"
+ exit_code |= 4
else
- installed = installed? name, options[:version]
+ installed = installed? name.first, options[:version]
installed = !installed unless options[:installed]
if installed then
@@ -95,6 +105,22 @@ is too hard to use.
terminate_interaction exit_code
end
+ names = Array(name)
+ names.each { |n| show_gems n, prerelease }
+ end
+
+ private
+
+ def display_header type
+ if (ui.outs.tty? and Gem.configuration.verbose) or both? then
+ say
+ say "*** #{type} GEMS ***"
+ say
+ end
+ end
+
+ #Guts of original execute
+ def show_gems name, prerelease
req = Gem::Requirement.default
# TODO: deprecate for real
dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req }
@@ -105,11 +131,7 @@ is too hard to use.
alert_warning "prereleases are always shown locally"
end
- if ui.outs.tty? or both? then
- say
- say "*** LOCAL GEMS ***"
- say
- end
+ display_header 'LOCAL'
specs = Gem::Specification.find_all { |s|
s.name =~ name and req =~ s.version
@@ -123,11 +145,7 @@ is too hard to use.
end
if remote? then
- if ui.outs.tty? or both? then
- say
- say "*** REMOTE GEMS ***"
- say
- end
+ display_header 'REMOTE'
fetcher = Gem::SpecFetcher.fetcher
@@ -155,8 +173,6 @@ is too hard to use.
end
end
- private
-
##
# Check if gem +name+ version +version+ is installed.