class Gem::CommandManager
The command manager registers and installs all the individual sub-commands supported by the gem command.
Extra commands can be provided by writing a rubygems_plugin.rb file in an installed gem. You should register your command against theGem::CommandManager instance, like this:
# file rubygems_plugin.rbrequire'rubygems/command_manager'Gem::CommandManager.instance.register_command:edit
You should put the implementation of your command in rubygems/commands.
# file rubygems/commands/edit_command.rbclassGem::Commands::EditCommand<Gem::Command# ...end
SeeGem::Command for instructions on writing gem commands.
Constants
- ALIAS_COMMANDS
Public Class Methods
Source
# File lib/rubygems/command_manager.rb, line 87defself.instance@instance||=newend
Return the authoritative instance of the command manager.
Source
# File lib/rubygems/command_manager.rb, line 109definitializerequire_relative"vendored_timeout"@commands = {}BUILTIN_COMMANDS.eachdo|name|register_commandnameendend
Register all the subcommands supported by the gem command.
Source
# File lib/rubygems/command_manager.rb, line 102defself.reset@instance =nilend
Reset the authoritative instance of the command manager.
Public Instance Methods
Source
# File lib/rubygems/command_manager.rb, line 135def[](command_name)command_name =command_name.internreturnnilif@commands[command_name].nil?@commands[command_name]||=load_and_instantiate(command_name)end
Returns a Command instance forcommand_name
Source
# File lib/rubygems/command_manager.rb, line 144defcommand_names@commands.keys.collect(&:to_s).sortend
Return a sorted list of all command names as strings.
Source
# File lib/rubygems/command_manager.rb, line 213deffind_alias_command(cmd_name)alias_name =ALIAS_COMMANDS[cmd_name]alias_name?alias_name:cmd_nameend
Source
# File lib/rubygems/command_manager.rb, line 198deffind_command(cmd_name)cmd_name =find_alias_commandcmd_namepossibilities =find_command_possibilitiescmd_nameifpossibilities.size>1raiseGem::CommandLineError,"Ambiguous command #{cmd_name} matches [#{possibilities.join(", ")}]"elsifpossibilities.empty?raiseGem::UnknownCommandError.new(cmd_name)endself[possibilities.first]end
Source
# File lib/rubygems/command_manager.rb, line 218deffind_command_possibilities(cmd_name)len =cmd_name.lengthfound =command_names.select {|name|cmd_name==name[0,len] }exact =found.find {|name|name==cmd_name }exact? [exact]:foundend
Source
# File lib/rubygems/command_manager.rb, line 95definstanceselfend
Returns self. Allows aCommandManager instance to stand in for the class itself.
Source
# File lib/rubygems/command_manager.rb, line 168defprocess_args(args,build_args =nil)ifargs.empty?sayGem::Command::HELPterminate_interaction1endcaseargs.firstwhen"-h","--help"thensayGem::Command::HELPterminate_interaction0when"-v","--version"thensayGem::VERSIONterminate_interaction0when"-C"thenargs.shiftstart_point =args.shiftifDir.exist?(start_point)Dir.chdir(start_point) {invoke_command(args,build_args) }elsealert_errorclean_text("#{start_point} isn't a directory.")terminate_interaction1endwhen/^-/thenalert_errorclean_text("Invalid option: #{args.first}. See 'gem --help'.")terminate_interaction1elseinvoke_command(args,build_args)endend
Source
# File lib/rubygems/command_manager.rb, line 121defregister_command(command,obj =false)@commands[command] =objend
Register theSymbolcommand as a gem command.
Source
# File lib/rubygems/command_manager.rb, line 151defrun(args,build_args =nil)process_args(args,build_args)rescueStandardError,Gem::Timeout::Error=>exifex.respond_to?(:detailed_message)msg =ex.detailed_message(highlight:false).sub(/\A(.*?)(?: \(.+?\))/) {$1 }elsemsg =ex.messageendalert_errorclean_text("While executing gem ... (#{ex.class})\n #{msg}")ui.backtraceexterminate_interaction(1)rescueInterruptalert_errorclean_text("Interrupted")terminate_interaction(1)end
Run the command specified byargs.
Source
# File lib/rubygems/command_manager.rb, line 128defunregister_command(command)@commands.deletecommandend
Unregister theSymbolcommand as a gem command.
Private Instance Methods
Source
# File lib/rubygems/command_manager.rb, line 248definvoke_command(args,build_args)cmd_name =args.shift.downcasecmd =find_commandcmd_nameterminate_interaction1unlesscmdcmd.deprecation_warningifcmd.deprecated?cmd.invoke_with_build_argsargs,build_argsend
Source
# File lib/rubygems/command_manager.rb, line 230defload_and_instantiate(command_name)command_name =command_name.to_sconst_name =command_name.capitalize.gsub(/_(.)/) {$1.upcase }<<"Command"beginbeginrequire"rubygems/commands/#{command_name}_command"rescueLoadError# it may have been defined from a rubygems_plugin.rb fileendGem::Commands.const_get(const_name).newrescueStandardError=>ealert_errorclean_text("Loading command: #{command_name} (#{e.class})\n\t#{e}")ui.backtraceeendend