/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/commands/environment_command.rb

http://github.com/agross/netopenspace · Ruby · 130 lines · 105 code · 25 blank · 0 comment · 7 complexity · 65ecc6bf98680080ea6c003a2af3c7fc MD5 · raw file

  1. require 'rubygems/command'
  2. class Gem::Commands::EnvironmentCommand < Gem::Command
  3. def initialize
  4. super 'environment', 'Display information about the RubyGems environment'
  5. end
  6. def arguments # :nodoc:
  7. args = <<-EOF
  8. packageversion display the package version
  9. gemdir display the path where gems are installed
  10. gempath display path used to search for gems
  11. version display the gem format version
  12. remotesources display the remote gem servers
  13. platform display the supported gem platforms
  14. <omitted> display everything
  15. EOF
  16. return args.gsub(/^\s+/, '')
  17. end
  18. def description # :nodoc:
  19. <<-EOF
  20. The RubyGems environment can be controlled through command line arguments,
  21. gemrc files, environment variables and built-in defaults.
  22. Command line argument defaults and some RubyGems defaults can be set in
  23. ~/.gemrc file for individual users and a /etc/gemrc for all users. A gemrc
  24. is a YAML file with the following YAML keys:
  25. :sources: A YAML array of remote gem repositories to install gems from
  26. :verbose: Verbosity of the gem command. false, true, and :really are the
  27. levels
  28. :update_sources: Enable/disable automatic updating of repository metadata
  29. :backtrace: Print backtrace when RubyGems encounters an error
  30. :gempath: The paths in which to look for gems
  31. gem_command: A string containing arguments for the specified gem command
  32. Example:
  33. :verbose: false
  34. install: --no-wrappers
  35. update: --no-wrappers
  36. RubyGems' default local repository can be overridden with the GEM_PATH and
  37. GEM_HOME environment variables. GEM_HOME sets the default repository to
  38. install into. GEM_PATH allows multiple local repositories to be searched for
  39. gems.
  40. If you are behind a proxy server, RubyGems uses the HTTP_PROXY,
  41. HTTP_PROXY_USER and HTTP_PROXY_PASS environment variables to discover the
  42. proxy server.
  43. If you are packaging RubyGems all of RubyGems' defaults are in
  44. lib/rubygems/defaults.rb. You may override these in
  45. lib/rubygems/defaults/operating_system.rb
  46. EOF
  47. end
  48. def usage # :nodoc:
  49. "#{program_name} [arg]"
  50. end
  51. def execute
  52. out = ''
  53. arg = options[:args][0]
  54. case arg
  55. when /^packageversion/ then
  56. out << Gem::RubyGemsPackageVersion
  57. when /^version/ then
  58. out << Gem::VERSION
  59. when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then
  60. out << Gem.dir
  61. when /^gempath/, /^path/, /^GEM_PATH/ then
  62. out << Gem.path.join(File::PATH_SEPARATOR)
  63. when /^remotesources/ then
  64. out << Gem.sources.join("\n")
  65. when /^platform/ then
  66. out << Gem.platforms.join(File::PATH_SEPARATOR)
  67. when nil then
  68. out = "RubyGems Environment:\n"
  69. out << " - RUBYGEMS VERSION: #{Gem::VERSION}\n"
  70. out << " - RUBY VERSION: #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
  71. out << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
  72. out << ") [#{RUBY_PLATFORM}]\n"
  73. out << " - INSTALLATION DIRECTORY: #{Gem.dir}\n"
  74. out << " - RUBYGEMS PREFIX: #{Gem.prefix}\n" unless Gem.prefix.nil?
  75. out << " - RUBY EXECUTABLE: #{Gem.ruby}\n"
  76. out << " - EXECUTABLE DIRECTORY: #{Gem.bindir}\n"
  77. out << " - RUBYGEMS PLATFORMS:\n"
  78. Gem.platforms.each do |platform|
  79. out << " - #{platform}\n"
  80. end
  81. out << " - GEM PATHS:\n"
  82. out << " - #{Gem.dir}\n"
  83. path = Gem.path.dup
  84. path.delete Gem.dir
  85. path.each do |p|
  86. out << " - #{p}\n"
  87. end
  88. out << " - GEM CONFIGURATION:\n"
  89. Gem.configuration.each do |name, value|
  90. value = value.gsub(/./, '*') if name == 'gemcutter_key'
  91. out << " - #{name.inspect} => #{value.inspect}\n"
  92. end
  93. out << " - REMOTE SOURCES:\n"
  94. Gem.sources.each do |s|
  95. out << " - #{s}\n"
  96. end
  97. else
  98. raise Gem::CommandLineError, "Unknown environment option [#{arg}]"
  99. end
  100. say out
  101. true
  102. end
  103. end