Class Gem::Commands::QueryCommand
In: lib/rubygems/commands/query_command.rb
Parent: Gem::Command

Methods

execute   new  

Included Modules

Gem::Text Gem::LocalRemoteOptions Gem::VersionOption

Public Class methods

[Source]

    # File lib/rubygems/commands/query_command.rb, line 13
13:   def initialize(name = 'query',
14:                  summary = 'Query gem information in local or remote repositories')
15:     super name, summary,
16:          :name => //, :domain => :local, :details => false, :versions => true,
17:          :installed => false, :version => Gem::Requirement.default
18: 
19:     add_option('-i', '--[no-]installed',
20:                'Check for installed gem') do |value, options|
21:       options[:installed] = value
22:     end
23: 
24:     add_version_option command, "for use with --installed"
25: 
26:     add_option('-n', '--name-matches REGEXP',
27:                'Name of gem(s) to query on matches the',
28:                'provided REGEXP') do |value, options|
29:       options[:name] = /#{value}/i
30:     end
31: 
32:     add_option('-d', '--[no-]details',
33:                'Display detailed information of gem(s)') do |value, options|
34:       options[:details] = value
35:     end
36: 
37:     add_option(      '--[no-]versions',
38:                'Display only gem names') do |value, options|
39:       options[:versions] = value
40:       options[:details] = false unless value
41:     end
42: 
43:     add_option('-a', '--all',
44:                'Display all gem versions') do |value, options|
45:       options[:all] = value
46:     end
47: 
48:     add_option(      '--[no-]prerelease',
49:                'Display prerelease versions') do |value, options|
50:       options[:prerelease] = value
51:     end
52: 
53:     add_local_remote_options
54:   end

Public Instance methods

[Source]

     # File lib/rubygems/commands/query_command.rb, line 60
 60:   def execute
 61:     exit_code = 0
 62: 
 63:     name = options[:name]
 64:     prerelease = options[:prerelease]
 65: 
 66:     if options[:installed] then
 67:       if name.source.empty? then
 68:         alert_error "You must specify a gem name"
 69:         exit_code |= 4
 70:       elsif installed? name, options[:version] then
 71:         say "true"
 72:       else
 73:         say "false"
 74:         exit_code |= 1
 75:       end
 76: 
 77:       terminate_interaction exit_code
 78:     end
 79: 
 80:     req = Gem::Requirement.default
 81:     # TODO: deprecate for real
 82:     dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req }
 83: 
 84:     if local? then
 85:       if prerelease and not both? then
 86:         alert_warning "prereleases are always shown locally"
 87:       end
 88: 
 89:       if ui.outs.tty? or both? then
 90:         say
 91:         say "*** LOCAL GEMS ***"
 92:         say
 93:       end
 94: 
 95:       specs = Gem::Specification.find_all { |s|
 96:         s.name =~ name and req =~ s.version
 97:       }
 98: 
 99:       spec_tuples = specs.map do |spec|
100:         [[spec.name, spec.version, spec.original_platform, spec], :local]
101:       end
102: 
103:       output_query_results spec_tuples
104:     end
105: 
106:     if remote? then
107:       if ui.outs.tty? or both? then
108:         say
109:         say "*** REMOTE GEMS ***"
110:         say
111:       end
112: 
113:       all = options[:all]
114: 
115:       fetcher = Gem::SpecFetcher.fetcher
116:       spec_tuples = fetcher.find_matching dep, all, false, prerelease
117: 
118:       spec_tuples += fetcher.find_matching dep, false, false, true if
119:         prerelease and all
120: 
121:       output_query_results spec_tuples
122:     end
123:   end

[Validate]