Environment UI class can now be set through the environment init
This commit is contained in:
parent
4d71b7bba3
commit
1355487a04
26
bin/vagrant
26
bin/vagrant
|
@ -7,25 +7,23 @@ require 'vagrant/cli'
|
|||
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
|
||||
env = Vagrant::Environment.new(opts)
|
||||
|
||||
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!
|
||||
|
|
|
@ -63,7 +63,8 @@ module Vagrant
|
|||
:vm => nil,
|
||||
:cwd => nil,
|
||||
:vagrantfile_name => nil,
|
||||
:lock_path => nil
|
||||
:lock_path => nil,
|
||||
:ui_class => nil
|
||||
}.merge(opts || {})
|
||||
|
||||
# Set the default working directory to look for the vagrantfile
|
||||
|
@ -75,9 +76,13 @@ module Vagrant
|
|||
opts[:vagrantfile_name] ||= ["Vagrantfile", "vagrantfile"]
|
||||
opts[:vagrantfile_name] = [opts[:vagrantfile_name]] if !opts[:vagrantfile_name].is_a?(Array)
|
||||
|
||||
opts.each do |key, value|
|
||||
instance_variable_set("@#{key}".to_sym, opts[key])
|
||||
end
|
||||
# Set instance variables for all the configuration parameters.
|
||||
@parent = opts[:parent]
|
||||
@vm = opts[:vm]
|
||||
@cwd = opts[:cwd]
|
||||
@vagrantfile_name = opts[:vagrantfile_name]
|
||||
@lock_path = opts[:lock_path]
|
||||
@ui_class = opts[:ui_class]
|
||||
|
||||
@loaded = false
|
||||
@lock_acquired = false
|
||||
|
@ -245,7 +250,8 @@ module Vagrant
|
|||
result.env = self
|
||||
result
|
||||
else
|
||||
UI::Silent.new(self)
|
||||
ui_class = @ui_class || UI::Silent
|
||||
ui_class.new(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
require "rubygems"
|
||||
require "rspec/autorun"
|
||||
|
||||
# Require Vagrant itself so we can reference the proper
|
||||
# classes to test.
|
||||
require "vagrant"
|
||||
|
||||
# Do not buffer output
|
||||
$stdout.sync = true
|
||||
$stderr.sync = true
|
||||
|
||||
# Configure RSpec
|
||||
RSpec.configure do |c|
|
||||
c.expect_with :rspec, :stdlib
|
||||
end
|
|
@ -0,0 +1,30 @@
|
|||
require File.expand_path("../../base", __FILE__)
|
||||
|
||||
require "pathname"
|
||||
|
||||
describe Vagrant::Environment do
|
||||
describe "current working directory" do
|
||||
it "is the cwd by default" do
|
||||
described_class.new.cwd.should == Pathname.new(Dir.pwd)
|
||||
end
|
||||
|
||||
it "is set to the cwd given" do
|
||||
instance = described_class.new(:cwd => "foobarbaz")
|
||||
instance.cwd.should == Pathname.new("foobarbaz")
|
||||
end
|
||||
end
|
||||
|
||||
describe "ui" do
|
||||
it "should be a silent UI by default" do
|
||||
described_class.new.ui.should be_kind_of(Vagrant::UI::Silent)
|
||||
end
|
||||
|
||||
it "should be a UI given in the constructor" do
|
||||
# Create a custom UI for our test
|
||||
class CustomUI < Vagrant::UI::Interface; end
|
||||
|
||||
instance = described_class.new(:ui_class => CustomUI)
|
||||
instance.ui.should be_kind_of(CustomUI)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue