    # File lib/rubygems/commands/query_command.rb, line 53
      def execute
        exit_code = 0

        name = options[:name]

        if options[:installed] then
          if name.source.empty? then
            alert_error "You must specify a gem name"
            exit_code |= 4
          elsif installed? name.source, options[:version] then
            say "true"
          else
            say "false"
            exit_code |= 1
          end

          raise Gem::SystemExitException, exit_code
        end

        if local? then
          say
          say "*** LOCAL GEMS ***"
          say

          specs = Gem.source_index.search name

          spec_tuples = specs.map do |spec|
            [[spec.name, spec.version, spec.original_platform, spec], :local]
          end

          output_query_results spec_tuples
        end

        if remote? then
          say
          say "*** REMOTE GEMS ***"
          say

          all = options[:all]

          dep = Gem::Dependency.new name, Gem::Requirement.default
          begin
            fetcher = Gem::SpecFetcher.fetcher
            spec_tuples = fetcher.find_matching dep, all, false
          rescue Gem::RemoteFetcher::FetchError => e
            raise unless fetcher.warn_legacy e do
              require 'rubygems/source_info_cache'

              dep.name = '' if dep.name == //

              specs = Gem::SourceInfoCache.search_with_source dep, false, all

              spec_tuples = specs.map do |spec, source_uri|
                [[spec.name, spec.version, spec.original_platform, spec],
                 source_uri]
              end
            end
          end

          output_query_results spec_tuples
        end
      end