def execute
options[:args] << '.' if options[:args].empty?
specs = {}
source_indexes = []
if local? then
source_indexes << Gem::SourceIndex.from_installed_gems
end
if remote? then
Gem::SourceInfoCache.cache_data.map do |_, sice|
source_indexes << sice.source_index
end
end
options[:args].each do |name|
new_specs = nil
source_indexes.each do |source_index|
new_specs = find_gems(name, source_index)
end
say "No match found for #{name} (#{options[:version]})" if
new_specs.empty?
specs = specs.merge new_specs
end
terminate_interaction 1 if specs.empty?
reverse = Hash.new { |h, k| h[k] = [] }
if options[:reverse_dependencies] then
specs.values.each do |source_index, spec|
reverse[spec.full_name] = find_reverse_dependencies spec, source_index
end
end
if options[:pipe_format] then
specs.values.sort_by { |_, spec| spec }.each do |_, spec|
unless spec.dependencies.empty?
spec.dependencies.each do |dep|
say "#{dep.name} --version '#{dep.version_requirements}'"
end
end
end
else
response = ''
specs.values.sort_by { |_, spec| spec }.each do |_, spec|
response << print_dependencies(spec)
unless reverse[spec.full_name].empty? then
response << " Used by\n"
reverse[spec.full_name].each do |sp, dep|
response << " #{sp} (#{dep})\n"
end
end
response << "\n"
end
say response
end
end