1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Initial support for gem-uninstall

This commit is contained in:
Kannan Manickam 2013-08-05 17:47:50 -07:00 committed by Kannan Manickam
parent 5701f61a41
commit 358e2b461c
2 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,28 @@
class Pry
class Command::GemUninstall < Pry::ClassCommand
match 'gem-uninstall'
group 'Gems'
description 'Uninstall a gem and refresh the gem cache.'
command_options :argument_required => true
banner <<-'BANNER'
Usage: gem-uninstall GEM_NAME
Uninstalls the given gem and refreshes the gem cache
gem-uninstall pry-stack_explorer
BANNER
def setup
require 'rubygems/uninstaller' unless defined? Gem::Uninstaller
end
def process(gem)
puts "Uninstalling gem #{gem}"
Rubygem.uninstall(gem)
output.puts "Gem `#{ text.green(gem) }` uninstalled."
end
end
Pry::Commands.add_command(Pry::Command::GemUninstall)
end

View file

@ -76,6 +76,23 @@ class Pry
else
Gem.refresh
end
# Uninstalls a gem.
#
# @param [String] name the name of the gem to uninstall
#
def uninstall(name)
uninstaller = Gem::Uninstaller.new(name)
uninstaller.uninstall
rescue Errno::EACCES
raise CommandError,
"Insufficient permissions to uninstall #{ Pry::Helpers::Text.green(name) }."
rescue Gem::InstallError
raise CommandError,
"Gem #{ Pry::Helpers::Text.green(name) } is not installed. Aborting uninstallation."
else
Gem.refresh
end
end
end