#!/usr/bin/env ruby require 'log4r' require 'vagrant' require 'vagrant/cli' # Create a logger right away logger = Log4r::Logger.new("vagrant::bin::vagrant") logger.info("`vagrant` invoked: #{ARGV.inspect}") # These will be the options that are passed to initialze the Vagrant # environment. opts = {} # Disable color if the proper argument was passed if !$stdout.tty? || ARGV.include?("--no-color") opts[:ui_class] = Vagrant::UI::Basic else opts[:ui_class] = Vagrant::UI::Colored end # 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) begin # Load the environment logger.debug("Loading environment") env.load! # Kick start the CLI Vagrant::CLI.start(ARGV, :env => env) rescue Vagrant::Errors::VagrantError => e logger.error("Vagrant experienced an error! Details:") logger.error(e.inspect) logger.error(e.message) logger.error(e.backtrace.join("\n")) opts = { :prefix => false } env.ui.error e.message, opts if e.message exit e.status_code if e.respond_to?(:status_code) exit 999 # An error occurred with no status code defined end