diff --git a/bin/vagrant b/bin/vagrant index 464e88b0d..0e6738953 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -20,25 +20,17 @@ if argv.include?("-v") || argv.include?("--version") exit 0 end -# This is kind of hacky, and I'd love to find a better way to do this, but -# if we're accessing the plugin interface, we want to NOT load plugins -# for this run, because they can actually interfere with the function -# of the plugin interface. +# Disable plugin loading for commands where plugins are not required argv.each_index do |i| arg = argv[i] if !arg.start_with?("-") - if arg == "plugin" - ENV["VAGRANT_NO_PLUGINS"] = "1" - ENV["VAGRANT_VAGRANTFILE"] = "plugin_command_#{Time.now.to_i}" + if ["plugin", "help"].include?(arg) || (arg == "box" && argv[i+1] == "list") + ENV['VAGRANT_NO_PLUGINS'] = "1" end - if arg == "help" - ENV["VAGRANT_VAGRANTFILE"] = "plugin_command_#{Time.now.to_i}" - end - - if arg == "box" && argv[i+1] == "list" - ENV["VAGRANT_VAGRANTFILE"] = "plugin_command_#{Time.now.to_i}" + if arg == "plugin" && argv[i+1] == "repair" + ENV['VAGRANT_DISABLE_PLUGIN_INIT'] = "1" end break @@ -57,7 +49,7 @@ end begin require "bundler" rescue Errno::EINVAL - # Bundler can generated the EINVAL error during initial require, which means + # Bundler can generate the EINVAL error during initial require, which means # nothing has yet been setup (so no access to I18n). Note that vagrant has # failed early and copy information related to problem and possible solution. $stderr.puts "Vagrant failed to initialize at a very early stage:\n\n" @@ -70,32 +62,34 @@ rescue Errno::EINVAL exit 255 end -begin - $vagrant_bundler_runtime = Bundler.setup(:default, :plugins) -rescue Bundler::GemNotFound - $stderr.puts "Bundler, the underlying system used to manage Vagrant plugins," - $stderr.puts "is reporting that a plugin or its dependency can't be found." - $stderr.puts "This is usually caused by manual tampering with the 'plugins.json'" - $stderr.puts "file in the Vagrant home directory. To fix this error, please" - $stderr.puts "remove that file and reinstall all your plugins using `vagrant" - $stderr.puts "plugin install`." -rescue Bundler::VersionConflict => e - $stderr.puts "Vagrant experienced a version conflict with some installed plugins!" - $stderr.puts "This usually happens if you recently upgraded Vagrant. As part of the" - $stderr.puts "upgrade process, some existing plugins are no longer compatible with" - $stderr.puts "this version of Vagrant. The recommended way to fix this is to remove" - $stderr.puts "your existing plugins and reinstall them one-by-one. To remove all" - $stderr.puts "plugins:" - $stderr.puts "" - $stderr.puts " rm -r ~/.vagrant.d/plugins.json ~/.vagrant.d/gems" - $stderr.puts "" - $stderr.puts "Note if you have an alternate VAGRANT_HOME environmental variable" - $stderr.puts "set, the folders above will be in that directory rather than your" - $stderr.puts "user's home directory." - $stderr.puts "" - $stderr.puts "The error message is shown below:\n\n" - $stderr.puts e.message - exit 1 +if(defined?(Bundler)) + begin + $vagrant_bundler_runtime = Bundler.setup(:default, :plugins) + rescue Bundler::GemNotFound + $stderr.puts "Bundler, the underlying system used to manage Vagrant plugins," + $stderr.puts "is reporting that a plugin or its dependency can't be found." + $stderr.puts "This is usually caused by manual tampering with the 'plugins.json'" + $stderr.puts "file in the Vagrant home directory. To fix this error, please" + $stderr.puts "remove that file and reinstall all your plugins using `vagrant" + $stderr.puts "plugin install`." + rescue Bundler::VersionConflict => e + $stderr.puts "Vagrant experienced a version conflict with some installed plugins!" + $stderr.puts "This usually happens if you recently upgraded Vagrant. As part of the" + $stderr.puts "upgrade process, some existing plugins are no longer compatible with" + $stderr.puts "this version of Vagrant. The recommended way to fix this is to remove" + $stderr.puts "your existing plugins and reinstall them one-by-one. To remove all" + $stderr.puts "plugins:" + $stderr.puts "" + $stderr.puts " rm -r ~/.vagrant.d/plugins.json ~/.vagrant.d/gems" + $stderr.puts "" + $stderr.puts "Note if you have an alternate VAGRANT_HOME environmental variable" + $stderr.puts "set, the folders above will be in that directory rather than your" + $stderr.puts "user's home directory." + $stderr.puts "" + $stderr.puts "The error message is shown below:\n\n" + $stderr.puts e.message + exit 1 + end end # Stdout/stderr should not buffer output diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 25227e055..193fb7b0a 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -256,7 +256,7 @@ end # Setup the plugin manager and load any defined plugins require_relative "vagrant/plugin/manager" plugins = Vagrant::Plugin::Manager.instance.installed_plugins -Vagrant::Bundler.instance.init!(plugins) +Vagrant::Bundler.instance.init!(plugins) unless ENV['VAGRANT_DISABLE_PLUGIN_INIT'] == "1" # A lambda that knows how to load plugins from a single directory. plugin_load_proc = lambda do |directory|