summaryrefslogtreecommitdiff
path: root/lib/rubygems/commands/uninstall_command.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 22:46:50 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 22:46:50 +0000
commit4c2304f0004e9f1784540f3d36976aad9eab1f68 (patch)
treefe5d7f52b7e01644d0a57316aab03299ed0ee5c8 /lib/rubygems/commands/uninstall_command.rb
parent66cc0fa4abde68ae360ba2d2cdf4e44bc833e33a (diff)
* lib/rubygems: Import RubyGems from master as of commit b165260
* test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/commands/uninstall_command.rb')
-rw-r--r--lib/rubygems/commands/uninstall_command.rb28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb
index 68d170acb1..5db8a1ff22 100644
--- a/lib/rubygems/commands/uninstall_command.rb
+++ b/lib/rubygems/commands/uninstall_command.rb
@@ -1,6 +1,7 @@
require 'rubygems/command'
require 'rubygems/version_option'
require 'rubygems/uninstaller'
+require 'fileutils'
##
# Gem uninstaller command line tool
@@ -14,7 +15,7 @@ class Gem::Commands::UninstallCommand < Gem::Command
def initialize
super 'uninstall', 'Uninstall gems from the local repository',
:version => Gem::Requirement.default, :user_install => true,
- :check_dev => false
+ :install_dir => Gem.dir, :check_dev => false
add_option('-a', '--[no-]all',
'Uninstall all matching versions'
@@ -92,8 +93,31 @@ class Gem::Commands::UninstallCommand < Gem::Command
end
def execute
- # REFACTOR: stolen from cleanup_command
+ if options[:all] and not options[:args].empty? then
+ alert_error 'Gem names and --all may not be used together'
+ terminate_interaction 1
+ elsif options[:all] then
+ uninstall_all
+ else
+ uninstall_specific
+ end
+ end
+
+ def uninstall_all
+ install_dir = options[:install_dir]
+
+ dirs_to_be_emptied = Dir[File.join(install_dir, '*')]
+ dirs_to_be_emptied.delete_if { |dir| dir.end_with? 'build_info' }
+
+ dirs_to_be_emptied.each do |dir|
+ FileUtils.rm_rf Dir[File.join(dir, '*')]
+ end
+ alert("Successfully uninstalled all gems in #{install_dir}")
+ end
+
+ def uninstall_specific
deplist = Gem::DependencyList.new
+
get_all_gem_names.uniq.each do |name|
Gem::Specification.find_all_by_name(name).each do |spec|
deplist.add spec