PageRenderTime 66ms CodeModel.GetById 36ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

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