From 9ab5a7c2b171d8ba69edc8be8e67fe61cf6df777 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 25 Aug 2010 22:13:55 -0700 Subject: [PATCH] Switch the actions over to using the new UI objects. --- bin/vagrant | 4 ++-- lib/vagrant/action/box/destroy.rb | 2 +- lib/vagrant/action/box/download.rb | 12 +++++----- lib/vagrant/action/box/unpackage.rb | 2 +- lib/vagrant/action/box/verify.rb | 2 +- lib/vagrant/action/environment.rb | 5 ++++ lib/vagrant/action/general/package.rb | 4 ++-- lib/vagrant/action/vm/boot.rb | 10 ++++---- lib/vagrant/action/vm/check_box.rb | 2 +- .../action/vm/check_guest_additions.rb | 8 +++---- .../action/vm/clear_forwarded_ports.rb | 2 +- lib/vagrant/action/vm/clear_shared_folders.rb | 2 +- lib/vagrant/action/vm/customize.rb | 2 +- lib/vagrant/action/vm/destroy.rb | 2 +- .../vm/destroy_unused_network_interfaces.rb | 2 +- lib/vagrant/action/vm/disable_networks.rb | 2 +- lib/vagrant/action/vm/discard_state.rb | 2 +- lib/vagrant/action/vm/export.rb | 4 ++-- lib/vagrant/action/vm/forward_ports.rb | 10 ++++---- lib/vagrant/action/vm/halt.rb | 2 +- lib/vagrant/action/vm/import.rb | 4 ++-- lib/vagrant/action/vm/match_mac_address.rb | 2 +- lib/vagrant/action/vm/network.rb | 6 ++--- lib/vagrant/action/vm/nfs.rb | 4 ++-- lib/vagrant/action/vm/persist.rb | 2 +- lib/vagrant/action/vm/provision.rb | 4 ++-- lib/vagrant/action/vm/resume.rb | 2 +- lib/vagrant/action/vm/share_folders.rb | 8 +++---- lib/vagrant/action/vm/suspend.rb | 2 +- lib/vagrant/ui.rb | 24 +++++++++---------- test/vagrant/action/environment_test.rb | 4 ++++ 31 files changed, 75 insertions(+), 68 deletions(-) diff --git a/bin/vagrant b/bin/vagrant index 1fa798fc8..babaee67d 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -7,7 +7,7 @@ env = Vagrant::Environment.load! begin Vagrant::CLI.start(ARGV, :env => env) rescue Vagrant::VagrantError => e - env.ui.error e.message - env.ui.error e.backtrace.join("\n") if ENV["VAGRANT_DEBUG"] + env.ui.error e.message, false + env.ui.error e.backtrace.join("\n"), false if ENV["VAGRANT_DEBUG"] exit e.status_code end diff --git a/lib/vagrant/action/box/destroy.rb b/lib/vagrant/action/box/destroy.rb index 28d36458f..dec9f5730 100644 --- a/lib/vagrant/action/box/destroy.rb +++ b/lib/vagrant/action/box/destroy.rb @@ -10,7 +10,7 @@ module Vagrant end def call(env) - env.logger.info "Deleting box directory..." + env.ui.info "Deleting box directory..." FileUtils.rm_rf(env["box"].directory) @app.call(env) diff --git a/lib/vagrant/action/box/download.rb b/lib/vagrant/action/box/download.rb index 0545583c6..66a4c2a5b 100644 --- a/lib/vagrant/action/box/download.rb +++ b/lib/vagrant/action/box/download.rb @@ -22,14 +22,14 @@ module Vagrant return if env.error? @app.call(@env) - + recover(env) # called in both cases to cleanup workspace end - + def instantiate_downloader @env["download.classes"].each do |klass| if klass.match?(@env["box"].uri) - @env.logger.info "Downloading with #{klass}..." + @env.ui.info "Downloading with #{klass}..." @downloader = klass.new(@env) end end @@ -52,13 +52,13 @@ module Vagrant def recover(env) if temp_path && File.exist?(temp_path) - env.logger.info "Cleaning up downloaded box..." + env.ui.info "Cleaning up downloaded box..." File.unlink(temp_path) end end def with_tempfile - @env.logger.info "Creating tempfile for storing box file..." + @env.ui.info "Creating tempfile for storing box file..." File.open(box_temp_path, Platform.tar_file_options) do |tempfile| yield tempfile end @@ -69,7 +69,7 @@ module Vagrant end def download_to(f) - @env.logger.info "Copying box to temporary location..." + @env.ui.info "Copying box to temporary location..." @downloader.download!(@env["box"].uri, f) end end diff --git a/lib/vagrant/action/box/unpackage.rb b/lib/vagrant/action/box/unpackage.rb index f07bdc206..66d43674b 100644 --- a/lib/vagrant/action/box/unpackage.rb +++ b/lib/vagrant/action/box/unpackage.rb @@ -49,7 +49,7 @@ module Vagrant def decompress Dir.chdir(@env["box"].directory) do - @env.logger.info "Extracting box to #{@env["box"].directory}..." + @env.ui.info "Extracting box to #{@env["box"].directory}..." Archive::Tar::Minitar.unpack(@env["download.temp_path"], @env["box"].directory) end end diff --git a/lib/vagrant/action/box/verify.rb b/lib/vagrant/action/box/verify.rb index 285b92ba5..5d5059b94 100644 --- a/lib/vagrant/action/box/verify.rb +++ b/lib/vagrant/action/box/verify.rb @@ -9,7 +9,7 @@ module Vagrant def call(env) begin - env.logger.info "Verifying box..." + env.ui.info "Verifying box..." VirtualBox::Appliance.new(env["box"].ovf_file) rescue Exception return env.error!(:box_verification_failed) diff --git a/lib/vagrant/action/environment.rb b/lib/vagrant/action/environment.rb index aee42adb8..2111e0d03 100644 --- a/lib/vagrant/action/environment.rb +++ b/lib/vagrant/action/environment.rb @@ -34,6 +34,11 @@ module Vagrant env.logger end + # Returns a UI object from the environment + def ui + env.ui + end + # Flags the environment as erroneous. Stores the given key # and options until the end of the action sequence. # diff --git a/lib/vagrant/action/general/package.rb b/lib/vagrant/action/general/package.rb index 094f5e66b..00a80cfb6 100644 --- a/lib/vagrant/action/general/package.rb +++ b/lib/vagrant/action/general/package.rb @@ -60,7 +60,7 @@ module Vagrant FileUtils.mkdir_p(include_dir) @env["package.include"].each do |f| - @env.logger.info "Packaging additional file: #{f}" + @env.ui.info "Packaging additional file: #{f}" FileUtils.cp(f, include_dir) end end @@ -68,7 +68,7 @@ module Vagrant # Compress the exported file into a package def compress - @env.logger.info "Compressing package to #{tar_path}..." + @env.ui.info "Compressing package to #{tar_path}..." File.open(tar_path, Platform.tar_file_options) do |tar| Archive::Tar::Minitar::Output.open(tar) do |output| begin diff --git a/lib/vagrant/action/vm/boot.rb b/lib/vagrant/action/vm/boot.rb index 97d089312..657e2d736 100644 --- a/lib/vagrant/action/vm/boot.rb +++ b/lib/vagrant/action/vm/boot.rb @@ -22,18 +22,18 @@ module Vagrant end def boot - @env.logger.info "Booting VM..." + @env.ui.info "Booting VM..." @env["vm"].vm.start(@env.env.config.vm.boot_mode) end def wait_for_boot - @env.logger.info "Waiting for VM to boot..." + @env.ui.info "Waiting for VM to boot..." @env.env.config.ssh.max_tries.to_i.times do |i| - @env.logger.info "Trying to connect (attempt ##{i+1} of #{@env.env.config[:ssh][:max_tries]})..." + @env.ui.info "Trying to connect (attempt ##{i+1} of #{@env.env.config[:ssh][:max_tries]})..." if @env["vm"].ssh.up? - @env.logger.info "VM booted and ready for use!" + @env.ui.info "VM booted and ready for use!" return true end @@ -44,7 +44,7 @@ module Vagrant sleep 5 if !@env["vagrant.test"] end - @env.logger.info "Failed to connect to VM! Failed to boot?" + @env.ui.error "Failed to connect to VM! Failed to boot?" false end end diff --git a/lib/vagrant/action/vm/check_box.rb b/lib/vagrant/action/vm/check_box.rb index cc6e9d291..cbf71d2b7 100644 --- a/lib/vagrant/action/vm/check_box.rb +++ b/lib/vagrant/action/vm/check_box.rb @@ -14,7 +14,7 @@ module Vagrant box_url = env["config"].vm.box_url return env.error!(:box_specified_doesnt_exist, :box_name => box_name) if !box_url - env.logger.info "Box #{box_name} not found. Fetching box since URL specified..." + env.ui.info "Box #{box_name} not found. Fetching box since URL specified..." Vagrant::Box.add(env.env, box_name, box_url) env.env.load_box! end diff --git a/lib/vagrant/action/vm/check_guest_additions.rb b/lib/vagrant/action/vm/check_guest_additions.rb index 4782c051b..118723580 100644 --- a/lib/vagrant/action/vm/check_guest_additions.rb +++ b/lib/vagrant/action/vm/check_guest_additions.rb @@ -16,11 +16,11 @@ module Vagrant # doesn't support guest properties (due to cross platform issues) version = env["vm"].vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version") if version.empty? - env.logger.error Translator.t(:vm_additions_not_detected) + env.ui.warn Translator.t(:vm_additions_not_detected) elsif version != VirtualBox.version - env.logger.error Translator.t(:vm_additions_version_mismatch, - :guest_additions_version => version, - :virtualbox_version => VirtualBox.version) + env.ui.warn Translator.t(:vm_additions_version_mismatch, + :guest_additions_version => version, + :virtualbox_version => VirtualBox.version) end # Continue diff --git a/lib/vagrant/action/vm/clear_forwarded_ports.rb b/lib/vagrant/action/vm/clear_forwarded_ports.rb index 6a985adf7..81c76bb80 100644 --- a/lib/vagrant/action/vm/clear_forwarded_ports.rb +++ b/lib/vagrant/action/vm/clear_forwarded_ports.rb @@ -19,7 +19,7 @@ module Vagrant def clear if used_ports.length > 0 - @env.logger.info "Deleting any previously set forwarded ports..." + @env.ui.info "Deleting any previously set forwarded ports..." clear_ports @env["vm"].reload! end diff --git a/lib/vagrant/action/vm/clear_shared_folders.rb b/lib/vagrant/action/vm/clear_shared_folders.rb index 673a39d5e..e429a93b4 100644 --- a/lib/vagrant/action/vm/clear_shared_folders.rb +++ b/lib/vagrant/action/vm/clear_shared_folders.rb @@ -16,7 +16,7 @@ module Vagrant def clear_shared_folders if @env["vm"].vm.shared_folders.length > 0 - @env.logger.info "Clearing previously set shared folders..." + @env.ui.info "Clearing previously set shared folders..." folders = @env["vm"].vm.shared_folders.dup folders.each do |shared_folder| diff --git a/lib/vagrant/action/vm/customize.rb b/lib/vagrant/action/vm/customize.rb index 505dd665a..442b0fe94 100644 --- a/lib/vagrant/action/vm/customize.rb +++ b/lib/vagrant/action/vm/customize.rb @@ -8,7 +8,7 @@ module Vagrant def call(env) if !env.env.config.vm.proc_stack.empty? - env.logger.info "Running any VM customizations..." + env.ui.info "Running any VM customizations..." env.env.config.vm.run_procs!(env["vm"].vm) env["vm"].vm.save end diff --git a/lib/vagrant/action/vm/destroy.rb b/lib/vagrant/action/vm/destroy.rb index 4aa5a6109..53b24f2eb 100644 --- a/lib/vagrant/action/vm/destroy.rb +++ b/lib/vagrant/action/vm/destroy.rb @@ -7,7 +7,7 @@ module Vagrant end def call(env) - env.logger.info "Destroying VM and associated drives..." + env.ui.info "Destroying VM and associated drives..." env["vm"].vm.destroy(:destroy_medium => :delete) env["vm"].vm = nil env.env.update_dotfile diff --git a/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb b/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb index 43febf259..3176a8fe6 100644 --- a/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +++ b/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb @@ -21,7 +21,7 @@ module Vagrant # Destroy the network interface if there is only one # attached VM (which must be this VM) if interface.attached_vms.length == 1 - env.logger.info "Destroying unused network interface..." + env.ui.info "Destroying unused network interface..." interface.destroy end end diff --git a/lib/vagrant/action/vm/disable_networks.rb b/lib/vagrant/action/vm/disable_networks.rb index 289ff8762..6b5a3eb6f 100644 --- a/lib/vagrant/action/vm/disable_networks.rb +++ b/lib/vagrant/action/vm/disable_networks.rb @@ -16,7 +16,7 @@ module Vagrant next if adapter.attachment_type != :host_only if !logged - env.logger.info "Disabling host only networks..." + env.ui.info "Disabling host only networks..." logged = true end diff --git a/lib/vagrant/action/vm/discard_state.rb b/lib/vagrant/action/vm/discard_state.rb index 087ca69f0..6350b2702 100644 --- a/lib/vagrant/action/vm/discard_state.rb +++ b/lib/vagrant/action/vm/discard_state.rb @@ -10,7 +10,7 @@ module Vagrant def call(env) if env["vm"].vm.saved? - env.logger.info "Discarding saved state of VM..." + env.ui.info "Discarding saved state of VM..." env["vm"].vm.discard_state end diff --git a/lib/vagrant/action/vm/export.rb b/lib/vagrant/action/vm/export.rb index 1107d29c1..5993b1876 100644 --- a/lib/vagrant/action/vm/export.rb +++ b/lib/vagrant/action/vm/export.rb @@ -31,13 +31,13 @@ module Vagrant end def setup_temp_dir - @env.logger.info "Creating temporary directory for export..." + @env.ui.info "Creating temporary directory for export..." @temp_dir = @env["export.temp_dir"] = File.join(@env.env.tmp_path, Time.now.to_i.to_s) FileUtils.mkpath(@env["export.temp_dir"]) end def export - @env.logger.info "Exporting VM to #{ovf_path}..." + @env.ui.info "Exporting VM to #{ovf_path}..." @env["vm"].vm.export(ovf_path) do |progress| @env.logger.report_progress(progress.percent, 100, false) end diff --git a/lib/vagrant/action/vm/forward_ports.rb b/lib/vagrant/action/vm/forward_ports.rb index 05237df44..123ac9fc8 100644 --- a/lib/vagrant/action/vm/forward_ports.rb +++ b/lib/vagrant/action/vm/forward_ports.rb @@ -67,7 +67,7 @@ module Vagrant existing_ports << options[:hostport] # Notify the user - @env.logger.info "Fixed port collision: #{name} now on port #{options[:hostport]}" + @env.ui.info "Fixed port collision: #{name} now on port #{options[:hostport]}" end #-------------------------------------------------------------- @@ -82,7 +82,7 @@ module Vagrant end def forward_ports - @env.logger.info "Forwarding ports..." + @env.ui.info "Forwarding ports..." @env.env.config.vm.forwarded_ports.each do |name, options| adapter = options[:adapter] @@ -91,11 +91,11 @@ module Vagrant # Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these # attachment types has uncertain behaviour. if @env["vm"].vm.network_adapters[adapter].attachment_type == :nat - @env.logger.info "Forwarding \"#{name}\": #{options[:guestport]} on adapter \##{adapter+1} => #{options[:hostport]}" + @env.ui.info "Forwarding \"#{name}\": #{options[:guestport]} on adapter \##{adapter+1} => #{options[:hostport]}" forward_port(name, options) else - @env.logger.info "VirtualBox adapter \##{adapter+1} not configured as \"NAT\"." - @env.logger.info "Skipped port forwarding \"#{name}\": #{options[:guestport]} on adapter\##{adapter+1} => #{options[:hostport]}" + @env.ui.info "VirtualBox adapter \##{adapter+1} not configured as \"NAT\"." + @env.ui.info "Skipped port forwarding \"#{name}\": #{options[:guestport]} on adapter\##{adapter+1} => #{options[:hostport]}" end end diff --git a/lib/vagrant/action/vm/halt.rb b/lib/vagrant/action/vm/halt.rb index 1f57683ab..b9a2c4746 100644 --- a/lib/vagrant/action/vm/halt.rb +++ b/lib/vagrant/action/vm/halt.rb @@ -17,7 +17,7 @@ module Vagrant end if env["vm"].vm.state(true) != :powered_off - env.logger.info "Forcing shutdown of VM..." + env.ui.info "Forcing shutdown of VM..." env["vm"].vm.stop end diff --git a/lib/vagrant/action/vm/import.rb b/lib/vagrant/action/vm/import.rb index 6154db5a8..11868890e 100644 --- a/lib/vagrant/action/vm/import.rb +++ b/lib/vagrant/action/vm/import.rb @@ -7,7 +7,7 @@ module Vagrant end def call(env) - env.logger.info "Importing base VM (#{env.env.box.ovf_file})" + env.ui.info "Importing base VM (#{env.env.box.ovf_file})" begin # Import the virtual machine @@ -24,7 +24,7 @@ module Vagrant # Import completed successfully. Continue the chain @app.call(env) end - + def recover(env) # Interrupted, destroy the VM env["actions"].run(:destroy) diff --git a/lib/vagrant/action/vm/match_mac_address.rb b/lib/vagrant/action/vm/match_mac_address.rb index 93b27005d..7b8351701 100644 --- a/lib/vagrant/action/vm/match_mac_address.rb +++ b/lib/vagrant/action/vm/match_mac_address.rb @@ -7,7 +7,7 @@ module Vagrant end def call(env) - env.logger.info "Matching MAC addresses..." + env.ui.info "Matching MAC addresses..." env["vm"].vm.network_adapters.first.mac_address = env.env.config.vm.base_mac env["vm"].vm.save diff --git a/lib/vagrant/action/vm/network.rb b/lib/vagrant/action/vm/network.rb index f04e3917d..26acdc231 100644 --- a/lib/vagrant/action/vm/network.rb +++ b/lib/vagrant/action/vm/network.rb @@ -26,7 +26,7 @@ module Vagrant if !env.error? && enable_network? catch_action_exception(env) do - @env.logger.info "Enabling host only network..." + @env.ui.info "Enabling host only network..." @env["vm"].system.prepare_host_only_network @env.env.config.vm.network_options.compact.each do |network_options| @env["vm"].system.enable_host_only_network(network_options) @@ -61,7 +61,7 @@ module Vagrant # Enables and assigns the host only network to the proper # adapter on the VM, and saves the adapter. def assign_network - @env.logger.info "Preparing host only network..." + @env.ui.info "Preparing host only network..." @env.env.config.vm.network_options.compact.each do |network_options| adapter = @env["vm"].vm.network_adapters[network_options[:adapter]] @@ -93,7 +93,7 @@ module Vagrant return @env.error!(:network_not_found, :name => net_options[:name]) if net_options[:name] # One doesn't exist, create it. - @env.logger.info "Creating new host only network for environment..." + @env.ui.info "Creating new host only network for environment..." ni = interfaces.create ni.enable_static(network_ip(net_options[:ip], net_options[:netmask]), diff --git a/lib/vagrant/action/vm/nfs.rb b/lib/vagrant/action/vm/nfs.rb index 476420bef..62fa68d61 100644 --- a/lib/vagrant/action/vm/nfs.rb +++ b/lib/vagrant/action/vm/nfs.rb @@ -104,7 +104,7 @@ module Vagrant # involves adding a line to `/etc/exports` for this VM, but it is # up to the host class to define the specific behavior. def export_folders - @env.logger.info "Exporting NFS shared folders..." + @env.ui.info "Exporting NFS shared folders..." catch_action_exception(@env) do @env["host"].nfs_export(guest_ip, folders) @@ -113,7 +113,7 @@ module Vagrant # Uses the system class to mount the NFS folders. def mount_folders - @env.logger.info "Mounting NFS shared folders..." + @env.ui.info "Mounting NFS shared folders..." catch_action_exception(@env) do @env["vm"].system.mount_nfs(host_ip, folders) diff --git a/lib/vagrant/action/vm/persist.rb b/lib/vagrant/action/vm/persist.rb index 73f37852b..8a763ff03 100644 --- a/lib/vagrant/action/vm/persist.rb +++ b/lib/vagrant/action/vm/persist.rb @@ -11,7 +11,7 @@ module Vagrant end def call(env) - env.logger.info "Persisting the VM UUID (#{env["vm"].uuid})" + env.ui.info "Persisting the VM UUID (#{env["vm"].uuid})" env.env.update_dotfile @app.call(env) diff --git a/lib/vagrant/action/vm/provision.rb b/lib/vagrant/action/vm/provision.rb index aa5da22d0..fb3403b1e 100644 --- a/lib/vagrant/action/vm/provision.rb +++ b/lib/vagrant/action/vm/provision.rb @@ -13,7 +13,7 @@ module Vagrant @app.call(env) if !env.error? && provisioning_enabled? - @env.logger.info "Beginning provisioning process..." + @env.ui.info "Beginning provisioning process..." @provisioner.provision! end end @@ -40,7 +40,7 @@ module Vagrant @provisioner = provisioner_klass.new(@env) end - @env.logger.info "Provisioning enabled with #{@provisioner.class}" + @env.ui.info "Provisioning enabled with #{@provisioner.class}" @provisioner.prepare @provisioner end diff --git a/lib/vagrant/action/vm/resume.rb b/lib/vagrant/action/vm/resume.rb index 9add4fef8..cf5c5348c 100644 --- a/lib/vagrant/action/vm/resume.rb +++ b/lib/vagrant/action/vm/resume.rb @@ -8,7 +8,7 @@ module Vagrant def call(env) if env["vm"].vm.saved? - env.logger.info "Resuming suspended VM..." + env.ui.info "Resuming suspended VM..." env["actions"].run(Boot) end diff --git a/lib/vagrant/action/vm/share_folders.rb b/lib/vagrant/action/vm/share_folders.rb index 56c249c1b..9ba9828d4 100644 --- a/lib/vagrant/action/vm/share_folders.rb +++ b/lib/vagrant/action/vm/share_folders.rb @@ -60,7 +60,7 @@ module Vagrant end def create_metadata - @env.logger.info "Creating shared folders metadata..." + @env.ui.info "Creating shared folders metadata..." shared_folders.each do |name, data| folder = VirtualBox::SharedFolder.new @@ -73,11 +73,11 @@ module Vagrant end def mount_shared_folders - @env.logger.info "Mounting shared folders..." + @env.ui.info "Mounting shared folders..." @env["vm"].ssh.execute do |ssh| shared_folders.each do |name, data| - @env.logger.info "-- #{name}: #{data[:guestpath]}" + @env.ui.info "-- #{name}: #{data[:guestpath]}" @env["vm"].system.mount_shared_folder(ssh, name, data[:guestpath]) end end @@ -89,7 +89,7 @@ module Vagrant @env["vm"].ssh.execute do |ssh| @env["vm"].system.prepare_unison(ssh) - @env.logger.info "Creating unison crontab entries..." + @env.ui.info "Creating unison crontab entries..." unison_folders.each do |name, data| @env["vm"].system.create_unison(ssh, data) end diff --git a/lib/vagrant/action/vm/suspend.rb b/lib/vagrant/action/vm/suspend.rb index abda51e63..8a6823141 100644 --- a/lib/vagrant/action/vm/suspend.rb +++ b/lib/vagrant/action/vm/suspend.rb @@ -8,7 +8,7 @@ module Vagrant def call(env) if env["vm"].vm.running? - env.logger.info "Saving VM state and suspending execution..." + env.ui.info "Saving VM state and suspending execution..." env["vm"].vm.save_state end diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index 52c56b1cc..77aa5ec60 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -9,9 +9,9 @@ module Vagrant @env = env end - [:warn, :error, :info, :confirm].each do |method| + [:warn, :error, :info, :confirm, :say_with_vm].each do |method| # By default these methods don't do anything. A silent UI. - define_method(method) { |message| } + define_method(method) { |*args| } end # A shell UI, which uses a `Thor::Shell` object to talk with @@ -23,20 +23,18 @@ module Vagrant @shell = shell end - def warn(message) - @shell.say(message, :yellow) + [[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color| + define_method(method) do |message, prepend_vm_name=true| + message = format_message(message) if prepend_vm_name + @shell.say(message, color) + end end - def error(message) - @shell.say(message, :red) - end + protected - def info(message) - @shell.say(message) - end - - def confirm(message) - @shell.say(message, :green) + def format_message(message) + name = env.vm_name || "vagrant" + "[#{name}] #{message}" end end end diff --git a/test/vagrant/action/environment_test.rb b/test/vagrant/action/environment_test.rb index 566462606..a89c2196e 100644 --- a/test/vagrant/action/environment_test.rb +++ b/test/vagrant/action/environment_test.rb @@ -15,6 +15,10 @@ class ActionEnvironmentTest < Test::Unit::TestCase assert_equal @instance.env.logger, @instance.logger end + should "setup the UI" do + assert_equal @instance.env.ui, @instance.ui + end + should "not be erroneous initially" do assert !@instance.error? end