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 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
# 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: fetcher = Gem::SpecFetcher.fetcher 112: spec_tuples = fetcher.find_matching dep, all, false, prerelease 113: 114: spec_tuples += fetcher.find_matching dep, false, false, true if 115: prerelease and all 116: 117: output_query_results spec_tuples 118: end 119: end