Class: Gem::EnvironmentCommand

Inherits:
Command
  • Object
show all
Includes:
CommandAids
Defined in:
lib/rubygems/gem_commands.rb

Instance Attribute Summary

Attributes inherited from Command

#command, #defaults, #options, #program_name, #summary

Instance Method Summary collapse

Methods included from CommandAids

#begins?, #get_all_gem_names, #get_one_gem_name, #get_one_optional_argument

Methods inherited from Command

add_common_option, #add_option, add_specific_extra_args, common_options, #defaults_str, extra_args, extra_args=, #handles?, #invoke, #merge_options, #remove_option, #show_help, specific_extra_args, specific_extra_args_hash, #when_invoked

Methods included from DefaultUserInteraction

#ui, ui, #ui=, ui=, #use_ui, use_ui

Constructor Details

#initializeEnvironmentCommand

Returns a new instance of EnvironmentCommand.



1270
1271
1272
# File 'lib/rubygems/gem_commands.rb', line 1270

def initialize
  super('environment', 'Display information about the RubyGems environment')
end

Instance Method Details

#argumentsObject



1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
# File 'lib/rubygems/gem_commands.rb', line 1278

def arguments
  args = <<-EOF
    packageversion  display the package version
    gemdir          display the path where gems are installed
    gempath         display path used to search for gems
    version         display the gem format version
    remotesources   display the remote gem servers
    <omitted>       display everything
  EOF
  return args.gsub(/^\s+/, '')
end

#executeObject



1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
# File 'lib/rubygems/gem_commands.rb', line 1290

def execute
  out = ''
  arg = options[:args][0]
  if begins?("packageversion", arg)
    out = Gem::RubyGemsPackageVersion.to_s
  elsif begins?("version", arg)
    out = Gem::RubyGemsVersion.to_s
  elsif begins?("gemdir", arg)
    out = Gem.dir
  elsif begins?("gempath", arg)
    Gem.path.collect { |p| out << "#{p}\n" }
  elsif begins?("remotesources", arg)
    require 'sources'
    out << Gem.sources.join("\n") << "\n"
  elsif arg
    fail Gem::CommandLineError, "Unknown enviroment option [#{arg}]"
  else
    out = "RubyGems Environment:\n"
    out << "  - VERSION: #{Gem::RubyGemsVersion} (#{Gem::RubyGemsPackageVersion})\n"
    out << "  - INSTALLATION DIRECTORY: #{Gem.dir}\n"
    out << "  - GEM PATH:\n"
    Gem.path.collect { |p| out << "     - #{p}\n" }
    out << "  - REMOTE SOURCES:\n"
    require 'sources'
    Gem.sources.collect do |s|
      out << "     - #{s}\n"
    end
  end
  say out
  true
end

#usageObject



1274
1275
1276
# File 'lib/rubygems/gem_commands.rb', line 1274

def usage
  "#{program_name} [args]"
end