Command::InstallCommand: honor ".gemrc" switches
Fix issue #666 (install-command doesn't seem to honor gemrc) Also, prettify various messages from "install-command".
This commit is contained in:
parent
f3ef105221
commit
5ff295c283
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue