From 23e82594e14930afc220b98e95a674d6b1912033 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 12 Mar 2014 22:41:41 -0300 Subject: [PATCH] backports: Add Action::Message --- lib/vagrant-backports/action/message.rb | 22 ++++++++++++++++++++-- lib/vagrant-lxc/action.rb | 16 ++++++++-------- lib/vagrant-lxc/action/message.rb | 23 ----------------------- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/lib/vagrant-backports/action/message.rb b/lib/vagrant-backports/action/message.rb index 7709396..1bf7a15 100644 --- a/lib/vagrant-backports/action/message.rb +++ b/lib/vagrant-backports/action/message.rb @@ -1,2 +1,20 @@ -# TODO: Implement this for vagrant < 1.5 -raise 'Action::Message has not been backported yet!' +module Vagrant + module Backports + module Action + # This middleware simply outputs a message to the UI. + class Message + def initialize(app, env, message, **opts) + @app = app + @message = message + end + + def call(env) + env[:ui].info(@message) + @app.call(env) + end + end + end + end +end + +Vagrant::Action::Builtin.const_set :Message, Vagrant::Backports::Action::Message diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index f3c4652..4eb6ed5 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -14,7 +14,6 @@ require 'vagrant-lxc/action/forced_halt' require 'vagrant-lxc/action/forward_ports' require 'vagrant-lxc/action/handle_box_metadata' require 'vagrant-lxc/action/is_running' -require 'vagrant-lxc/action/message' require 'vagrant-lxc/action/prepare_nfs_settings' require 'vagrant-lxc/action/prepare_nfs_valid_ids' require 'vagrant-lxc/action/remove_temporary_files' @@ -27,6 +26,7 @@ end unless Vagrant::Backports.vagrant_1_5_or_later? require 'vagrant-backports/ui' require 'vagrant-backports/action/handle_box' + require 'vagrant-backports/action/message' end module Vagrant @@ -43,7 +43,7 @@ module Vagrant Builder.new.tap do |b| b.use Builtin::Call, Created do |env1, b2| if !env1[:result] - b2.use Message, :not_created + b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") next end @@ -84,13 +84,13 @@ module Vagrant b.use Builtin::ConfigValidate b.use Builtin::Call, Created do |env1, b2| if !env1[:result] - b2.use Message, :not_created + b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") next end b2.use Builtin::Call, IsRunning do |env2, b3| if !env2[:result] - b3.use Message, :not_running + b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running") next end @@ -146,7 +146,7 @@ module Vagrant end end else - b2.use Message, :not_created + b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") end end end @@ -158,7 +158,7 @@ module Vagrant Builder.new.tap do |b| b.use Builtin::Call, Created do |env1, b2| if !env1[:result] - b2.use Message, :not_created + b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") next end @@ -173,7 +173,7 @@ module Vagrant b3.use Builtin::ProvisionerCleanup end else - b3.use Message, :will_not_destroy + b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.will_not_destroy") end end end @@ -185,7 +185,7 @@ module Vagrant Builder.new.tap do |b| b.use Builtin::Call, Created do |env1, b2| if !env1[:result] - b2.use Message, :not_created + b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created") next end diff --git a/lib/vagrant-lxc/action/message.rb b/lib/vagrant-lxc/action/message.rb index ca3d2ee..e69de29 100644 --- a/lib/vagrant-lxc/action/message.rb +++ b/lib/vagrant-lxc/action/message.rb @@ -1,23 +0,0 @@ -module Vagrant - module LXC - module Action - # XXX: Is this really needed? Should we contribute this back to Vagrant's core? - class Message - def initialize(app, env, msg_key, type = :info) - @app = app - @msg_key = msg_key - @type = type - end - - def call(env) - machine = env[:machine] - message = I18n.t("vagrant_lxc.messages.#{@msg_key}", name: machine.name) - - env[:ui].send @type, message - - @app.call env - end - end - end - end -end