vaguerent/bin/vagrant
2011-12-01 21:56:56 -08:00

42 lines
1.2 KiB
Ruby
Executable File

#!/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}")
# Create the environment, which is the cwd of wherever the
# `vagrant` command was invoked from
logger.debug("Creating Vagrant environment")
env = Vagrant::Environment.new
begin
# Disable color if the proper argument was passed
ui = nil
if !$stdout.tty? || ARGV.include?("--no-color")
ui = Vagrant::UI::Basic.new(env)
else
ui = Vagrant::UI::Colored.new(env)
end
# Set the UI early in case any errors are raised, and load
# the config immediately, so we gather any new commands from
# plugins
env.ui = ui
# Load the environment
logger.debug("Loading environment")
env.load!
# Kick start the CLI
Vagrant::CLI.start(ARGV, :env => env)
rescue Vagrant::Errors::VagrantError => e
opts = { :prefix => false }
env.ui.error e.message, opts if e.message
env.ui.error e.backtrace.join("\n"), opts if ENV["VAGRANT_DEBUG"]
exit e.status_code if e.respond_to?(:status_code)
exit 999 # An error occurred with no status code defined
end