| Class | Gem::Commands::QueryCommand |
| In: |
lib/rubygems/commands/query_command.rb
|
| Parent: | Gem::Command |
# 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
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( '--prerelease',
49: 'Display prerelease versions') do |value, options|
50: options[:prerelease] = value
51: end
52:
53: add_local_remote_options
54: end
# 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: raise Gem::SystemExitException, exit_code
78: end
79:
80: dep = Gem::Dependency.new name, Gem::Requirement.default
81:
82: if local? then
83: if prerelease and not both? then
84: alert_warning "prereleases are always shown locally"
85: end
86:
87: if ui.outs.tty? or both? then
88: say
89: say "*** LOCAL GEMS ***"
90: say
91: end
92:
93: specs = Gem.source_index.search dep
94:
95: spec_tuples = specs.map do |spec|
96: [[spec.name, spec.version, spec.original_platform, spec], :local]
97: end
98:
99: output_query_results spec_tuples
100: end
101:
102: if remote? then
103: if ui.outs.tty? or both? then
104: say
105: say "*** REMOTE GEMS ***"
106: say
107: end
108:
109: all = options[:all]
110:
111: begin
112: fetcher = Gem::SpecFetcher.fetcher
113: spec_tuples = fetcher.find_matching dep, all, false, prerelease
114: rescue Gem::RemoteFetcher::FetchError => e
115: if prerelease then
116: raise Gem::OperationNotSupportedError,
117: "Prereleases not supported on legacy repositories"
118: end
119:
120: raise unless fetcher.warn_legacy e do
121: require 'rubygems/source_info_cache'
122:
123: dep.name = '' if dep.name == //
124:
125: specs = Gem::SourceInfoCache.search_with_source dep, false, all
126:
127: spec_tuples = specs.map do |spec, source_uri|
128: [[spec.name, spec.version, spec.original_platform, spec],
129: source_uri]
130: end
131: end
132: end
133:
134: output_query_results spec_tuples
135: end
136: end