2010-01-30 06:21:35 +00:00
|
|
|
#!/usr/bin/env ruby
|
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 = {}
|
|
|
|
|
2012-01-06 07:03:20 +00:00
|
|
|
# Disable color if the proper argument was passed or if we're
|
|
|
|
# on Windows since the default Windows terminal doesn't support
|
|
|
|
# colors.
|
2012-01-20 19:25:39 +00:00
|
|
|
if ARGV.include?("--no-color") || !$stdout.tty? || !Vagrant::Util::Platform.terminal_supports_colors?
|
2011-12-18 22:00:27 +00:00
|
|
|
# Delete the argument from the list so that it doesn't cause any
|
|
|
|
# invalid arguments down the road.
|
|
|
|
ARGV.delete("--no-color")
|
2011-12-04 00:07:34 +00:00
|
|
|
opts[:ui_class] = Vagrant::UI::Basic
|
|
|
|
else
|
|
|
|
opts[:ui_class] = Vagrant::UI::Colored
|
|
|
|
end
|
|
|
|
|
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)
|
|
|
|
|
2011-12-01 05:43:57 +00:00
|
|
|
# Load the environment
|
|
|
|
logger.debug("Loading environment")
|
2010-09-21 07:47:50 +00:00
|
|
|
env.load!
|
|
|
|
|
2011-12-17 07:34:30 +00:00
|
|
|
# Execute the CLI interface
|
|
|
|
env.cli(ARGV)
|
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
|