1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/commands/install_command.rb
Kyrylo Silin ebccd57013 Convert all commands to classes
John "banister" Mair describes the following key features of commands
as classes:

  1. It enables people to extend them by either subclassing or
     monkeypatching.
  2. It enables them to provide their own API, so that for example, the
     Pry::Command::Edit class could have class methods for people to
     configure it.

Please, note that I didn't touch easter eggs commands. I also prettified
some strings (your source code reading experience should vastly improve!).

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
2012-12-27 13:31:37 +02:00

51 lines
1.5 KiB
Ruby

class Pry
class Command::InstallCommand < Pry::ClassCommand
match 'install-command'
group 'Commands'
description 'Install a disabled command.'
banner <<-BANNER
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|
next if gem_installed?(g)
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
Pry::Commands.add_command(Pry::Command::InstallCommand)
end