Class Gem::CommandManager
In: lib/rubygems/command_manager.rb
Parent: Object

The command manager registers and installs all the individual sub-commands supported by the gem command.

Methods

Included Modules

UserInteraction

Public Class methods

Return the authoratative instance of the command manager.

[Source]

    # File lib/rubygems/command_manager.rb, line 20
20:     def self.instance
21:       @command_manager ||= CommandManager.new
22:     end

Register all the subcommands supported by the gem command.

[Source]

    # File lib/rubygems/command_manager.rb, line 25
25:     def initialize
26:       @commands = {}
27:       register_command :build
28:       register_command :cert
29:       register_command :check
30:       register_command :cleanup
31:       register_command :contents
32:       register_command :dependency
33:       register_command :environment
34:       register_command :fetch
35:       register_command :generate_index
36:       register_command :help
37:       register_command :install
38:       register_command :list
39:       register_command :lock
40:       register_command :mirror
41:       register_command :outdated
42:       register_command :pristine
43:       register_command :query
44:       register_command :rdoc
45:       register_command :search
46:       register_command :server
47:       register_command :sources
48:       register_command :specification
49:       register_command :uninstall
50:       register_command :unpack
51:       register_command :update
52:       register_command :which
53:     end

Public Instance methods

Return the registered command from the command name.

[Source]

    # File lib/rubygems/command_manager.rb, line 61
61:     def [](command_name)
62:       command_name = command_name.intern
63:       return nil if @commands[command_name].nil?
64:       @commands[command_name] ||= load_and_instantiate(command_name)
65:     end

Return a list of all command names (as strings).

[Source]

    # File lib/rubygems/command_manager.rb, line 68
68:     def command_names
69:       @commands.keys.collect {|key| key.to_s}.sort
70:     end

[Source]

     # File lib/rubygems/command_manager.rb, line 108
108:     def find_command(cmd_name)
109:       possibilities = find_command_possibilities(cmd_name)
110:       if possibilities.size > 1
111:         raise "Ambiguous command #{cmd_name} matches [#{possibilities.join(', ')}]"
112:       end
113:       if possibilities.size < 1
114:         raise "Unknown command #{cmd_name}"
115:       end
116: 
117:       self[possibilities.first]
118:     end

[Source]

     # File lib/rubygems/command_manager.rb, line 120
120:     def find_command_possibilities(cmd_name)
121:       len = cmd_name.length
122:       self.command_names.select { |n| cmd_name == n[0,len] }
123:     end

[Source]

     # File lib/rubygems/command_manager.rb, line 85
 85:     def process_args(args)
 86:       args = args.to_str.split(/\s+/) if args.respond_to?(:to_str)
 87:       if args.size == 0
 88:         say Gem::Command::HELP
 89:         terminate_interaction(1)
 90:       end 
 91:       case args[0]
 92:       when '-h', '--help'
 93:         say Gem::Command::HELP
 94:         terminate_interaction(0)
 95:       when '-v', '--version'
 96:         say Gem::RubyGemsVersion
 97:         terminate_interaction(0)
 98:       when /^-/
 99:         alert_error "Invalid option: #{args[0]}.  See 'gem --help'."
100:         terminate_interaction(1)
101:       else
102:         cmd_name = args.shift.downcase
103:         cmd = find_command(cmd_name)
104:         cmd.invoke(*args)
105:       end
106:     end

Register the command object.

[Source]

    # File lib/rubygems/command_manager.rb, line 56
56:     def register_command(command_obj)
57:       @commands[command_obj] = false
58:     end

Run the config specificed by args.

[Source]

    # File lib/rubygems/command_manager.rb, line 73
73:     def run(args)
74:       process_args(args)
75:     rescue StandardError, Timeout::Error => ex
76:       alert_error "While executing gem ... (#{ex.class})\n    #{ex.to_s}"
77:       ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
78:         Gem.configuration.backtrace
79:       terminate_interaction(1)
80:     rescue Interrupt
81:       alert_error "Interrupted"
82:       terminate_interaction(1)
83:     end

[Validate]