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

http://github.com/agross/netopenspace · Ruby · 88 lines · 66 code · 18 blank · 4 comment · 0 complexity · d64b9885eaa038263d5297e426b83342 MD5 · raw file

  1. require 'rubygems/command'
  2. require 'rubygems/version_option'
  3. require 'rubygems/uninstaller'
  4. ##
  5. # Gem uninstaller command line tool
  6. #
  7. # See `gem help uninstall`
  8. class Gem::Commands::UninstallCommand < Gem::Command
  9. include Gem::VersionOption
  10. def initialize
  11. super 'uninstall', 'Uninstall gems from the local repository',
  12. :version => Gem::Requirement.default, :user_install => true
  13. add_option('-a', '--[no-]all',
  14. 'Uninstall all matching versions'
  15. ) do |value, options|
  16. options[:all] = value
  17. end
  18. add_option('-I', '--[no-]ignore-dependencies',
  19. 'Ignore dependency requirements while',
  20. 'uninstalling') do |value, options|
  21. options[:ignore] = value
  22. end
  23. add_option('-x', '--[no-]executables',
  24. 'Uninstall applicable executables without',
  25. 'confirmation') do |value, options|
  26. options[:executables] = value
  27. end
  28. add_option('-i', '--install-dir DIR',
  29. 'Directory to uninstall gem from') do |value, options|
  30. options[:install_dir] = File.expand_path(value)
  31. end
  32. add_option('-n', '--bindir DIR',
  33. 'Directory to remove binaries from') do |value, options|
  34. options[:bin_dir] = File.expand_path(value)
  35. end
  36. add_option('--[no-]user-install',
  37. 'Uninstall from user\'s home directory',
  38. 'in addition to GEM_HOME.') do |value, options|
  39. options[:user_install] = value
  40. end
  41. add_option('--[no-]format-executable',
  42. 'Assume executable names match Ruby\'s prefix and suffix.') do |value, options|
  43. options[:format_executable] = value
  44. end
  45. add_version_option
  46. add_platform_option
  47. end
  48. def arguments # :nodoc:
  49. "GEMNAME name of gem to uninstall"
  50. end
  51. def defaults_str # :nodoc:
  52. "--version '#{Gem::Requirement.default}' --no-force " \
  53. "--install-dir #{Gem.dir}\n" \
  54. "--user-install"
  55. end
  56. def usage # :nodoc:
  57. "#{program_name} GEMNAME [GEMNAME ...]"
  58. end
  59. def execute
  60. get_all_gem_names.each do |gem_name|
  61. begin
  62. Gem::Uninstaller.new(gem_name, options).uninstall
  63. rescue Gem::GemNotInHomeException => e
  64. spec = e.spec
  65. alert("In order to remove #{spec.name}, please execute:\n" \
  66. "\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}")
  67. end
  68. end
  69. end
  70. end