2010-01-30 06:21:35 +00:00
|
|
|
#!/usr/bin/env ruby
|
2012-08-10 07:30:58 +00:00
|
|
|
|
|
|
|
# Trap interrupts to quit cleanly. This will be overriden at some point
|
|
|
|
# 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
|
|
|
|
2014-01-05 23:27:03 +00:00
|
|
|
# Fast path the version of Vagrant
|
|
|
|
if argv.include?("-v") || argv.include?("--version")
|
|
|
|
puts "Vagrant #{Vagrant::VERSION}"
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
|
2014-01-05 23:26:44 +00:00
|
|
|
# First, make sure that we're executing using the proper Bundler context
|
|
|
|
# with our plugins. If we're not, then load that and reload Vagrant.
|
|
|
|
if !ENV["VAGRANT_INTERNAL_BUNDLERIZED"]
|
|
|
|
require "rbconfig"
|
|
|
|
ruby_path = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
|
|
|
|
Kernel.exec(
|
|
|
|
ruby_path,
|
|
|
|
File.expand_path("../../lib/vagrant/pre-rubygems.rb", __FILE__),
|
|
|
|
*ARGV)
|
|
|
|
raise "Fatal error: this line should never be reached"
|
|
|
|
end
|
|
|
|
|
2013-11-25 19:42:06 +00:00
|
|
|
# Split arguments by "--" if its there, we'll recombine them later
|
|
|
|
argv = ARGV.dup
|
|
|
|
argv_extra = []
|
|
|
|
if idx = argv.index("--")
|
|
|
|
argv_extra = argv.slice(idx+1, argv.length-2)
|
|
|
|
argv = argv.slice(0, idx)
|
|
|
|
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
|
|
|
|
|
2011-12-01 05:43:57 +00:00
|
|
|
require 'log4r'
|
2010-08-24 06:44:42 +00:00
|
|
|
require 'vagrant'
|
2010-08-24 16:21:24 +00:00
|
|
|
require 'vagrant/cli'
|
2012-01-06 07:03:20 +00:00
|
|
|
require 'vagrant/util/platform'
|
2010-01-30 06:21:35 +00:00
|
|
|
|
2011-12-01 05:43:57 +00:00
|
|
|
# Create a logger right away
|
|
|
|
logger = Log4r::Logger.new("vagrant::bin::vagrant")
|
|
|
|
logger.info("`vagrant` invoked: #{ARGV.inspect}")
|
|
|
|
|
2011-12-10 21:44:34 +00:00
|
|
|
# Stdout/stderr should not buffer output
|
|
|
|
$stdout.sync = true
|
|
|
|
$stderr.sync = true
|
|
|
|
|
2011-12-04 00:07:34 +00:00
|
|
|
# These will be the options that are passed to initialze the Vagrant
|
|
|
|
# environment.
|
|
|
|
opts = {}
|
|
|
|
|
2013-04-06 23:03:25 +00:00
|
|
|
# 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)
|
|
|
|
#
|
2013-11-25 19:42:06 +00:00
|
|
|
if argv.include?("--no-color") || ENV["VAGRANT_NO_COLOR"]
|
2013-04-06 23:03:25 +00:00
|
|
|
# Delete the argument from the list so that it doesn't
|
|
|
|
# cause any invalid arguments down the road.
|
2013-11-25 19:42:06 +00:00
|
|
|
argv.delete("--no-color")
|
2013-04-06 23:03:25 +00:00
|
|
|
|
|
|
|
opts[:ui_class] = Vagrant::UI::Basic
|
|
|
|
elsif !Vagrant::Util::Platform.terminal_supports_colors?
|
2011-12-04 00:07:34 +00:00
|
|
|
opts[:ui_class] = Vagrant::UI::Basic
|
2013-04-06 23:05:13 +00:00
|
|
|
elsif !$stdout.tty? && !Vagrant::Util::Platform.cygwin?
|
2013-10-24 06:20:27 +00:00
|
|
|
# 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
|
2011-12-04 00:07:34 +00:00
|
|
|
end
|
|
|
|
|
2013-08-09 18:40:08 +00:00
|
|
|
# Also allow users to force colors.
|
2013-11-25 19:42:06 +00:00
|
|
|
if argv.include?("--color")
|
|
|
|
argv.delete("--color")
|
2013-08-09 18:40:08 +00:00
|
|
|
opts[:ui_class] = Vagrant::UI::Colored
|
|
|
|
end
|
|
|
|
|
2013-11-24 19:04:54 +00:00
|
|
|
# Highest precedence is if we have enabled machine-readable output
|
2013-11-25 19:42:06 +00:00
|
|
|
if argv.include?("--machine-readable")
|
|
|
|
argv.delete("--machine-readable")
|
2013-11-24 19:11:38 +00:00
|
|
|
opts[:ui_class] = Vagrant::UI::MachineReadable
|
2013-11-24 19:04:54 +00:00
|
|
|
end
|
|
|
|
|
2013-04-06 23:03:25 +00:00
|
|
|
# Default to colored output
|
|
|
|
opts[:ui_class] ||= Vagrant::UI::Colored
|
|
|
|
|
2013-03-01 06:32:13 +00:00
|
|
|
# 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.
|
2013-11-25 19:42:06 +00:00
|
|
|
argv.each do |arg|
|
2013-03-01 06:32:13 +00:00
|
|
|
if !arg.start_with?("-")
|
2013-11-23 21:25:33 +00:00
|
|
|
if arg == "plugin"
|
|
|
|
ENV["VAGRANT_NO_PLUGINS"] = "1"
|
|
|
|
ENV["VAGRANT_VAGRANTFILE"] = "plugin_command_#{Time.now.to_i}"
|
|
|
|
end
|
|
|
|
|
2013-03-01 06:32:13 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-25 19:42:06 +00:00
|
|
|
# Recombine the arguments
|
|
|
|
argv << "--"
|
|
|
|
argv += argv_extra
|
|
|
|
|
2011-12-11 01:10:02 +00:00
|
|
|
env = nil
|
2010-08-24 16:21:24 +00:00
|
|
|
begin
|
2011-12-11 01:10:02 +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)
|
|
|
|
|
2013-03-29 00:10:07 +00:00
|
|
|
if !Vagrant.in_installer?
|
|
|
|
# If we're not in the installer, warn.
|
2014-01-05 00:29:22 +00:00
|
|
|
env.ui.warn(I18n.t("vagrant.general.not_in_installer"))
|
2013-03-29 00:10:07 +00:00
|
|
|
end
|
2013-01-28 21:39:56 +00:00
|
|
|
|
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)
|
2010-08-27 17:02:17 +00:00
|
|
|
rescue Vagrant::Errors::VagrantError => e
|
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
|
|
|
|
opts = { :prefix => false }
|
|
|
|
env.ui.error e.message, opts if e.message
|
|
|
|
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)
|
|
|
|
exit 999 # An error occurred with no status code defined
|
2010-08-24 16:21:24 +00:00
|
|
|
end
|