From 5ff295c283320cc0eb76aac927b2189963b10246 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Wed, 20 Feb 2013 13:02:34 +0200 Subject: [PATCH] Command::InstallCommand: honor ".gemrc" switches Fix issue #666 (install-command doesn't seem to honor gemrc) Also, prettify various messages from "install-command". --- lib/pry/commands/install_command.rb | 21 +++++++++------------ lib/pry/rubygem.rb | 14 +++++++++++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/pry/commands/install_command.rb b/lib/pry/commands/install_command.rb index e5193adc..5350c7ef 100644 --- a/lib/pry/commands/install_command.rb +++ b/lib/pry/commands/install_command.rb @@ -16,34 +16,31 @@ class Pry command = find_command(name) if command_dependencies_met?(command.options) - output.puts "Dependencies for #{command.name} are met. Nothing to do." + output.puts "Dependencies for #{ text.green(name) } are met. Nothing to do" return end - output.puts "Attempting to install `#{name}` command..." + output.puts "Attempting to install #{ text.green(name) } command..." gems_to_install = Array(command.options[:requires_gem]) gems_to_install.each do |g| next if Rubygem.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 + output.puts "Installing #{ text.green(g) } gem..." + Rubygem.install(g) 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." + fail_msg = "Required gem #{ text.green(g) } installed but not found." + fail_msg += " Aborting command installation\n" + fail_msg += 'Tips: 1. Check your PATH; 2. Run `bundle update`' + raise CommandError, fail_msg end end - output.puts "Installation of `#{name}` successful! Type `help #{name}` for information" + output.puts "Installation of #{ text.green(name) } successful! Type `help #{name}` for information" end end diff --git a/lib/pry/rubygem.rb b/lib/pry/rubygem.rb index ced2cd4b..ad8e1b70 100644 --- a/lib/pry/rubygem.rb +++ b/lib/pry/rubygem.rb @@ -57,14 +57,22 @@ class Pry # @param [String] name # @return [void] def install(name) - destination = File.writable?(Gem.dir) ? Gem.dir : Gem.user_dir + gemrc_opts = Gem.configuration['gem'].split(' ') + destination = if gemrc_opts.include?('--user-install') + Gem.user_dir + elsif File.writable?(Gem.dir) + Gem.dir + else + Gem.user_dir + end installer = Gem::DependencyInstaller.new(:install_dir => destination) installer.install(name) rescue Errno::EACCES raise CommandError, - "Insufficient permissions to install `#{ text.green(name) }`." + "Insufficient permissions to install #{ text.green(name) }." rescue Gem::GemNotFoundException - raise CommandError, "Gem `#{ text.green(name) }` not found." + raise CommandError, + "Gem #{ text.green(name) } not found. Aborting installation." else Gem.refresh end