| Class | Gem::Commands::QueryCommand |
| In: |
lib/rubygems/commands/query_command.rb
|
| Parent: | Gem::Command |
# File lib/rubygems/commands/query_command.rb, line 11
11: def initialize(name = 'query',
12: summary = 'Query gem information in local or remote repositories')
13: super name, summary,
14: :name => //, :domain => :local, :details => false, :versions => true,
15: :installed => false, :version => Gem::Requirement.default
16:
17: add_option('-i', '--[no-]installed',
18: 'Check for installed gem') do |value, options|
19: options[:installed] = value
20: end
21:
22: add_version_option
23:
24: add_option('-n', '--name-matches REGEXP',
25: 'Name of gem(s) to query on matches the',
26: 'provided REGEXP') do |value, options|
27: options[:name] = /#{value}/i
28: end
29:
30: add_option('-d', '--[no-]details',
31: 'Display detailed information of gem(s)') do |value, options|
32: options[:details] = value
33: end
34:
35: add_option( '--[no-]versions',
36: 'Display only gem names') do |value, options|
37: options[:versions] = value
38: options[:details] = false unless value
39: end
40:
41: add_option('-a', '--all',
42: 'Display all gem versions') do |value, options|
43: options[:all] = value
44: end
45:
46: add_local_remote_options
47: end
# File lib/rubygems/commands/query_command.rb, line 53
53: def execute
54: exit_code = 0
55:
56: name = options[:name]
57:
58: if options[:installed] then
59: if name.source.empty? then
60: alert_error "You must specify a gem name"
61: exit_code |= 4
62: elsif installed? name.source, options[:version] then
63: say "true"
64: else
65: say "false"
66: exit_code |= 1
67: end
68:
69: raise Gem::SystemExitException, exit_code
70: end
71:
72: if local? then
73: say
74: say "*** LOCAL GEMS ***"
75: say
76:
77: output_query_results Gem.source_index.search(name)
78: end
79:
80: if remote? then
81: say
82: say "*** REMOTE GEMS ***"
83: say
84:
85: all = options[:all]
86:
87: begin
88: Gem::SourceInfoCache.cache all
89: rescue Gem::RemoteFetcher::FetchError
90: # no network
91: end
92:
93: output_query_results Gem::SourceInfoCache.search(name, false, all)
94: end
95: end