2012-02-07 03:13:19 +00:00
|
|
|
require "rubygems"
|
|
|
|
require "rubygems/gem_runner"
|
|
|
|
|
2012-03-18 23:41:26 +00:00
|
|
|
require "vagrant/util/safe_puts"
|
|
|
|
|
2012-04-19 20:59:48 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module CommandGem
|
2012-11-07 05:05:14 +00:00
|
|
|
class Command < Vagrant.plugin("2", :command)
|
2012-04-19 20:59:48 +00:00
|
|
|
include Vagrant::Util::SafePuts
|
2012-03-18 23:41:26 +00:00
|
|
|
|
2012-02-07 03:13:19 +00:00
|
|
|
def execute
|
2012-02-07 03:21:01 +00:00
|
|
|
# Bundler sets up its own custom gem load paths such that our
|
|
|
|
# own gems are never loaded. Therefore, give an error if a user
|
|
|
|
# tries to install gems while within a Bundler-managed environment.
|
|
|
|
if defined?(Bundler)
|
|
|
|
require 'bundler/shared_helpers'
|
|
|
|
if Bundler::SharedHelpers.in_bundle?
|
2013-02-03 02:42:04 +00:00
|
|
|
raise Vagrant::Errors::GemCommandInBundler
|
2012-02-07 03:21:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-07 03:52:34 +00:00
|
|
|
# If the user needs some help, we add our own little message at the
|
|
|
|
# top so that they're aware of what `vagrant gem` is doing, really.
|
|
|
|
if @argv.empty? || @argv.include?("-h") || @argv.include?("--help")
|
|
|
|
@env.ui.info(I18n.t("vagrant.commands.gem.help_preamble"),
|
|
|
|
:prefix => false)
|
2012-03-18 23:41:26 +00:00
|
|
|
safe_puts
|
2012-02-07 03:52:34 +00:00
|
|
|
end
|
|
|
|
|
2012-02-07 03:13:19 +00:00
|
|
|
# We just proxy the arguments onto a real RubyGems command
|
|
|
|
# but change `GEM_HOME` so that the gems are installed into
|
|
|
|
# our own private gem folder.
|
|
|
|
ENV["GEM_HOME"] = @env.gems_path.to_s
|
|
|
|
::Gem.clear_paths
|
|
|
|
::Gem::GemRunner.new.run(@argv.dup)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|