Class | Gem::Commands::ContentsCommand |
In: |
lib/rubygems/commands/contents_command.rb
|
Parent: | Gem::Command |
# File lib/rubygems/commands/contents_command.rb, line 8 8: def initialize 9: super 'contents', 'Display the contents of the installed gems', 10: :specdirs => [], :lib_only => false 11: 12: add_version_option 13: 14: add_option('-s', '--spec-dir a,b,c', Array, 15: "Search for gems under specific paths") do |spec_dirs, options| 16: options[:specdirs] = spec_dirs 17: end 18: 19: add_option('-l', '--[no-]lib-only', 20: "Only return files in the Gem's lib_dirs") do |lib_only, options| 21: options[:lib_only] = lib_only 22: end 23: end
# File lib/rubygems/commands/contents_command.rb, line 37 37: def execute 38: version = options[:version] || Gem::Requirement.default 39: gem = get_one_gem_name 40: 41: s = options[:specdirs].map do |i| 42: [i, File.join(i, "specifications")] 43: end.flatten 44: 45: path_kind = if s.empty? then 46: s = Gem::SourceIndex.installed_spec_directories 47: "default gem paths" 48: else 49: "specified path" 50: end 51: 52: si = Gem::SourceIndex.from_gems_in(*s) 53: 54: gem_spec = si.find_name(gem, version).last 55: 56: unless gem_spec then 57: say "Unable to find gem '#{gem}' in #{path_kind}" 58: 59: if Gem.configuration.verbose then 60: say "\nDirectories searched:" 61: s.each { |dir| say dir } 62: end 63: 64: terminate_interaction 65: end 66: 67: files = options[:lib_only] ? gem_spec.lib_files : gem_spec.files 68: files.each do |f| 69: say File.join(gem_spec.full_gem_path, f) 70: end 71: end