2012-08-11 17:22:29 -07:00
|
|
|
class Pry
|
2012-12-25 23:35:17 +02:00
|
|
|
class Command::InstallCommand < Pry::ClassCommand
|
|
|
|
match 'install-command'
|
2012-08-11 17:22:29 -07:00
|
|
|
group 'Commands'
|
2012-12-25 23:35:17 +02:00
|
|
|
description 'Install a disabled command.'
|
2012-08-11 17:22:29 -07:00
|
|
|
|
2013-01-09 22:23:19 +02:00
|
|
|
banner <<-'BANNER'
|
2012-08-11 17:22:29 -07:00
|
|
|
Usage: install-command COMMAND
|
|
|
|
|
|
|
|
Installs the gems necessary to run the given COMMAND. You will generally not
|
|
|
|
need to run this unless told to by an error message.
|
|
|
|
BANNER
|
|
|
|
|
|
|
|
def process(name)
|
|
|
|
require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
|
|
|
|
command = find_command(name)
|
|
|
|
|
|
|
|
if command_dependencies_met?(command.options)
|
|
|
|
output.puts "Dependencies for #{command.name} are met. Nothing to do."
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
output.puts "Attempting to install `#{name}` command..."
|
|
|
|
gems_to_install = Array(command.options[:requires_gem])
|
|
|
|
|
|
|
|
gems_to_install.each do |g|
|
2013-01-09 00:24:53 +02:00
|
|
|
next if Rubygem.installed?(g)
|
2012-08-11 17:22:29 -07:00
|
|
|
output.puts "Installing `#{g}` gem..."
|
|
|
|
|
|
|
|
begin
|
|
|
|
Gem::DependencyInstaller.new.install(g)
|
|
|
|
rescue Gem::GemNotFoundException
|
|
|
|
raise CommandError, "Required Gem: `#{g}` not found. Aborting command installation."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem.refresh
|
|
|
|
gems_to_install.each do |g|
|
|
|
|
begin
|
|
|
|
require g
|
|
|
|
rescue LoadError
|
|
|
|
raise CommandError, "Required Gem: `#{g}` installed but not found?!. Aborting command installation."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
output.puts "Installation of `#{name}` successful! Type `help #{name}` for information"
|
|
|
|
end
|
|
|
|
end
|
2012-12-25 23:35:17 +02:00
|
|
|
|
|
|
|
Pry::Commands.add_command(Pry::Command::InstallCommand)
|
2012-08-11 17:22:29 -07:00
|
|
|
end
|