2010-01-30 06:21:35 +00:00
|
|
|
#!/usr/bin/env ruby
|
2012-08-10 07:30:58 +00:00
|
|
|
|
2014-04-29 10:36:32 +00:00
|
|
|
# Trap interrupts to quit cleanly. This will be overridden at some point
|
2012-08-10 07:30:58 +00:00
|
|
|
# by Vagrant. This is made to catch any interrupts while Vagrant is
|
|
|
|
# initializing which have historically resulted in stack traces.
|
2014-01-03 16:32:45 +00:00
|
|
|
Signal.trap("INT") { abort }
|
2012-08-10 07:30:58 +00:00
|
|
|
|
2018-04-26 21:58:05 +00:00
|
|
|
# Disable exception reporting by default if available
|
|
|
|
if Thread.respond_to?(:report_on_exception=)
|
|
|
|
Thread.report_on_exception = false
|
|
|
|
end
|
|
|
|
|
2014-01-05 23:32:19 +00:00
|
|
|
# Split arguments by "--" if its there, we'll recombine them later
|
|
|
|
argv = ARGV.dup
|
|
|
|
argv_extra = []
|
2016-12-01 03:41:59 +00:00
|
|
|
|
2018-03-14 14:41:04 +00:00
|
|
|
# These will be the options that are passed to initialize the Vagrant
|
2016-12-01 03:41:59 +00:00
|
|
|
# environment.
|
|
|
|
opts = {}
|
|
|
|
|
2014-01-05 23:32:19 +00:00
|
|
|
if idx = argv.index("--")
|
|
|
|
argv_extra = argv.slice(idx+1, argv.length-2)
|
|
|
|
argv = argv.slice(0, idx)
|
|
|
|
end
|
|
|
|
|
2014-01-05 23:27:03 +00:00
|
|
|
# Fast path the version of Vagrant
|
|
|
|
if argv.include?("-v") || argv.include?("--version")
|
2014-10-24 11:31:51 +00:00
|
|
|
require_relative "../lib/vagrant/version"
|
2014-01-05 23:27:03 +00:00
|
|
|
puts "Vagrant #{Vagrant::VERSION}"
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
|
2016-12-01 03:41:59 +00:00
|
|
|
# Disable plugin loading for commands where plugins are not required. This will
|
|
|
|
# also disable loading of the Vagrantfile if it available as the environment
|
|
|
|
# is not required for these commands
|
2014-04-19 03:46:02 +00:00
|
|
|
argv.each_index do |i|
|
|
|
|
arg = argv[i]
|
|
|
|
|
2014-01-06 00:16:04 +00:00
|
|
|
if !arg.start_with?("-")
|
2018-05-08 20:46:44 +00:00
|
|
|
if arg == "box" && argv[i+1] == "list"
|
2016-12-01 03:41:59 +00:00
|
|
|
opts[:vagrantfile_name] = ""
|
2016-11-02 17:35:23 +00:00
|
|
|
ENV['VAGRANT_NO_PLUGINS'] = "1"
|
2014-01-06 00:16:04 +00:00
|
|
|
end
|
|
|
|
|
2018-05-08 20:46:44 +00:00
|
|
|
# Do not load plugins when performing plugin operations
|
|
|
|
if arg == "plugin"
|
2018-07-18 17:50:06 +00:00
|
|
|
if argv.none?{|a| a == "--local" } && !ENV["VAGRANT_LOCAL_PLUGINS_LOAD"]
|
2018-07-17 22:00:38 +00:00
|
|
|
opts[:vagrantfile_name] = ""
|
|
|
|
end
|
2018-05-08 20:46:44 +00:00
|
|
|
ENV['VAGRANT_NO_PLUGINS'] = "1"
|
|
|
|
# Only initialize plugins when listing installed plugins
|
|
|
|
if argv[i+1] != "list"
|
|
|
|
ENV['VAGRANT_DISABLE_PLUGIN_INIT'] = "1"
|
|
|
|
end
|
2014-04-19 03:46:02 +00:00
|
|
|
end
|
|
|
|
|
2014-01-06 00:16:04 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-01 01:12:34 +00:00
|
|
|
# Set logging level to `debug`. This is done before loading 'vagrant', as it
|
|
|
|
# sets up the logging system.
|
2013-11-25 19:42:06 +00:00
|
|
|
if argv.include?("--debug")
|
|
|
|
argv.delete("--debug")
|
2013-11-01 01:12:34 +00:00
|
|
|
ENV["VAGRANT_LOG"] = "debug"
|
|
|
|
end
|
|
|
|
|
2017-12-14 01:05:51 +00:00
|
|
|
# Enable log timestamps if requested
|
|
|
|
if argv.include?("--timestamp")
|
|
|
|
argv.delete("--timestamp")
|
|
|
|
ENV["VAGRANT_LOG_TIMESTAMP"] = "1"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Convenience flag to enable debug with timestamps
|
|
|
|
if argv.include?("--debug-timestamp")
|
|
|
|
argv.delete("--debug-timestamp")
|
|
|
|
ENV["VAGRANT_LOG"] = "debug"
|
|
|
|
ENV["VAGRANT_LOG_TIMESTAMP"] = "1"
|
|
|
|
end
|
|
|
|
|
2011-12-10 21:44:34 +00:00
|
|
|
# Stdout/stderr should not buffer output
|
|
|
|
$stdout.sync = true
|
|
|
|
$stderr.sync = true
|
|
|
|
|
2014-01-08 22:45:43 +00:00
|
|
|
env = nil
|
|
|
|
begin
|
|
|
|
require 'log4r'
|
|
|
|
require 'vagrant'
|
2014-08-08 23:47:37 +00:00
|
|
|
require 'vagrant/bundler'
|
2014-01-08 22:45:43 +00:00
|
|
|
require 'vagrant/cli'
|
|
|
|
require 'vagrant/util/platform'
|
2018-12-07 18:27:47 +00:00
|
|
|
require 'vagrant/util/experimental'
|
2014-01-08 22:45:43 +00:00
|
|
|
|
2014-08-08 23:47:37 +00:00
|
|
|
# Schedule the cleanup of things
|
|
|
|
at_exit(&Vagrant::Bundler.instance.method(:deinit))
|
|
|
|
|
2014-01-08 22:45:43 +00:00
|
|
|
# Create a logger right away
|
|
|
|
logger = Log4r::Logger.new("vagrant::bin::vagrant")
|
|
|
|
logger.info("`vagrant` invoked: #{ARGV.inspect}")
|
|
|
|
|
|
|
|
# Disable color in a few cases:
|
|
|
|
#
|
|
|
|
# * --no-color is anywhere in our arguments
|
|
|
|
# * STDOUT is not a TTY
|
|
|
|
# * The terminal doesn't support colors (Windows)
|
|
|
|
#
|
|
|
|
if argv.include?("--no-color") || ENV["VAGRANT_NO_COLOR"]
|
|
|
|
# Delete the argument from the list so that it doesn't
|
|
|
|
# cause any invalid arguments down the road.
|
|
|
|
argv.delete("--no-color")
|
|
|
|
|
|
|
|
opts[:ui_class] = Vagrant::UI::Basic
|
|
|
|
elsif !Vagrant::Util::Platform.terminal_supports_colors?
|
|
|
|
opts[:ui_class] = Vagrant::UI::Basic
|
|
|
|
elsif !$stdout.tty? && !Vagrant::Util::Platform.cygwin?
|
|
|
|
# Cygwin always reports STDOUT is not a TTY, so we only disable
|
|
|
|
# colors if its not a TTY AND its not Cygwin.
|
|
|
|
opts[:ui_class] = Vagrant::UI::Basic
|
|
|
|
end
|
2011-12-04 00:07:34 +00:00
|
|
|
|
2014-01-08 22:45:43 +00:00
|
|
|
# Also allow users to force colors.
|
2016-05-30 19:54:24 +00:00
|
|
|
if argv.include?("--color") || ENV["VAGRANT_FORCE_COLOR"]
|
2014-01-08 22:45:43 +00:00
|
|
|
argv.delete("--color")
|
|
|
|
opts[:ui_class] = Vagrant::UI::Colored
|
|
|
|
end
|
2013-08-09 18:40:08 +00:00
|
|
|
|
2014-01-08 22:45:43 +00:00
|
|
|
# Highest precedence is if we have enabled machine-readable output
|
|
|
|
if argv.include?("--machine-readable")
|
|
|
|
argv.delete("--machine-readable")
|
|
|
|
opts[:ui_class] = Vagrant::UI::MachineReadable
|
|
|
|
end
|
2013-11-24 19:04:54 +00:00
|
|
|
|
2014-01-08 22:45:43 +00:00
|
|
|
# Default to colored output
|
|
|
|
opts[:ui_class] ||= Vagrant::UI::Colored
|
2013-04-06 23:03:25 +00:00
|
|
|
|
2014-01-08 22:45:43 +00:00
|
|
|
# Recombine the arguments
|
2014-04-15 23:33:41 +00:00
|
|
|
if !argv_extra.empty?
|
|
|
|
argv << "--"
|
|
|
|
argv += argv_extra
|
|
|
|
end
|
2013-11-25 19:42:06 +00:00
|
|
|
|
2017-05-08 22:20:21 +00:00
|
|
|
# Create the environment, which is the cwd of wherever the
|
|
|
|
# `vagrant` command was invoked from
|
|
|
|
logger.debug("Creating Vagrant environment")
|
|
|
|
env = Vagrant::Environment.new(opts)
|
|
|
|
|
2017-05-05 02:02:15 +00:00
|
|
|
# If we are running with the Windows Subsystem for Linux do
|
|
|
|
# some extra setup to allow access to Vagrant managed machines
|
|
|
|
# outside the subsystem
|
|
|
|
if Vagrant::Util::Platform.wsl?
|
2017-05-12 20:14:04 +00:00
|
|
|
recreate_env = Vagrant::Util::Platform.wsl_init(env, logger)
|
|
|
|
if recreate_env
|
|
|
|
logger.info("Re-creating Vagrant environment due to WSL modifications.")
|
|
|
|
env = Vagrant::Environment.new(opts)
|
|
|
|
end
|
2017-05-05 02:02:15 +00:00
|
|
|
end
|
|
|
|
|
2014-04-21 03:34:54 +00:00
|
|
|
if !Vagrant.in_installer? && !Vagrant.very_quiet?
|
2013-03-29 00:10:07 +00:00
|
|
|
# If we're not in the installer, warn.
|
2014-01-17 19:02:12 +00:00
|
|
|
env.ui.warn(I18n.t("vagrant.general.not_in_installer") + "\n", prefix: false)
|
2013-03-29 00:10:07 +00:00
|
|
|
end
|
2013-01-28 21:39:56 +00:00
|
|
|
|
2018-12-06 00:28:10 +00:00
|
|
|
# Acceptable experimental flag values include:
|
|
|
|
#
|
|
|
|
# Unset - Disables experimental features
|
|
|
|
# 0 - Disables experimental features
|
|
|
|
# 1 - Enables all features
|
|
|
|
# String - Enables one or more features, separated by commas
|
2018-12-07 21:30:50 +00:00
|
|
|
if Vagrant::Util::Experimental.enabled?
|
2018-12-07 18:27:47 +00:00
|
|
|
experimental = Vagrant::Util::Experimental.features_requested
|
|
|
|
ui = Vagrant::UI::Prefixed.new(env.ui, "vagrant")
|
|
|
|
logger.debug("Experimental flag is enabled")
|
2018-12-07 21:30:50 +00:00
|
|
|
if Vagrant::Util::Experimental.global_enabled?
|
2018-12-07 18:27:47 +00:00
|
|
|
ui.warn(I18n.t("vagrant.general.experimental.all"), bold: true, prefix: true, channel: :error)
|
2018-12-07 21:31:18 +00:00
|
|
|
else
|
|
|
|
ui.warn(I18n.t("vagrant.general.experimental.features", features: experimental.join(", ")), bold: true, prefix: true, channel: :error)
|
2018-12-06 00:28:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-03 08:09:40 +00:00
|
|
|
begin
|
|
|
|
# Execute the CLI interface, and exit with the proper error code
|
2013-11-25 19:42:06 +00:00
|
|
|
exit_status = env.cli(argv)
|
2013-03-03 08:09:40 +00:00
|
|
|
ensure
|
|
|
|
# Unload the environment so cleanup can be done
|
|
|
|
env.unload
|
|
|
|
end
|
2013-02-22 21:54:28 +00:00
|
|
|
|
|
|
|
# Exit with the exit status from our CLI command
|
|
|
|
exit(exit_status)
|
2014-01-09 04:04:48 +00:00
|
|
|
rescue Exception => e
|
|
|
|
# It is possible for errors to happen in Vagrant's initialization. In
|
|
|
|
# this case, we don't have access to this class yet, so we check for it.
|
|
|
|
raise if !defined?(Vagrant) || !defined?(Vagrant::Errors)
|
|
|
|
raise if !e.is_a?(Vagrant::Errors::VagrantError)
|
|
|
|
|
2014-01-08 22:45:43 +00:00
|
|
|
require 'log4r'
|
|
|
|
logger = Log4r::Logger.new("vagrant::bin::vagrant")
|
2011-12-04 01:16:49 +00:00
|
|
|
logger.error("Vagrant experienced an error! Details:")
|
|
|
|
logger.error(e.inspect)
|
|
|
|
logger.error(e.message)
|
|
|
|
logger.error(e.backtrace.join("\n"))
|
|
|
|
|
2011-12-11 01:10:02 +00:00
|
|
|
if env
|
2014-05-22 16:35:12 +00:00
|
|
|
opts = { prefix: false }
|
2011-12-11 01:10:02 +00:00
|
|
|
env.ui.error e.message, opts if e.message
|
2014-02-24 06:40:45 +00:00
|
|
|
env.ui.machine("error-exit", e.class.to_s, e.message.to_s)
|
2011-12-11 01:10:02 +00:00
|
|
|
else
|
|
|
|
$stderr.puts "Vagrant failed to initialize at a very early stage:\n\n"
|
|
|
|
$stderr.puts e.message
|
|
|
|
end
|
|
|
|
|
2010-08-28 19:23:40 +00:00
|
|
|
exit e.status_code if e.respond_to?(:status_code)
|
2014-05-04 08:33:30 +00:00
|
|
|
exit 255 # An error occurred with no status code defined
|
2010-08-24 16:21:24 +00:00
|
|
|
end
|