backports: Add Action::Message

This commit is contained in:
Fabio Rehm 2014-03-12 22:41:41 -03:00
parent 5c6855eb4c
commit 23e82594e1
3 changed files with 28 additions and 33 deletions

View file

@ -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

View file

@ -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

View file

@ -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