backports: Add Action::Message
This commit is contained in:
parent
5c6855eb4c
commit
23e82594e1
3 changed files with 28 additions and 33 deletions
|
@ -1,2 +1,20 @@
|
||||||
# TODO: Implement this for vagrant < 1.5
|
module Vagrant
|
||||||
raise 'Action::Message has not been backported yet!'
|
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
|
||||||
|
|
|
@ -14,7 +14,6 @@ require 'vagrant-lxc/action/forced_halt'
|
||||||
require 'vagrant-lxc/action/forward_ports'
|
require 'vagrant-lxc/action/forward_ports'
|
||||||
require 'vagrant-lxc/action/handle_box_metadata'
|
require 'vagrant-lxc/action/handle_box_metadata'
|
||||||
require 'vagrant-lxc/action/is_running'
|
require 'vagrant-lxc/action/is_running'
|
||||||
require 'vagrant-lxc/action/message'
|
|
||||||
require 'vagrant-lxc/action/prepare_nfs_settings'
|
require 'vagrant-lxc/action/prepare_nfs_settings'
|
||||||
require 'vagrant-lxc/action/prepare_nfs_valid_ids'
|
require 'vagrant-lxc/action/prepare_nfs_valid_ids'
|
||||||
require 'vagrant-lxc/action/remove_temporary_files'
|
require 'vagrant-lxc/action/remove_temporary_files'
|
||||||
|
@ -27,6 +26,7 @@ end
|
||||||
unless Vagrant::Backports.vagrant_1_5_or_later?
|
unless Vagrant::Backports.vagrant_1_5_or_later?
|
||||||
require 'vagrant-backports/ui'
|
require 'vagrant-backports/ui'
|
||||||
require 'vagrant-backports/action/handle_box'
|
require 'vagrant-backports/action/handle_box'
|
||||||
|
require 'vagrant-backports/action/message'
|
||||||
end
|
end
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
|
@ -43,7 +43,7 @@ module Vagrant
|
||||||
Builder.new.tap do |b|
|
Builder.new.tap do |b|
|
||||||
b.use Builtin::Call, Created do |env1, b2|
|
b.use Builtin::Call, Created do |env1, b2|
|
||||||
if !env1[:result]
|
if !env1[:result]
|
||||||
b2.use Message, :not_created
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,13 +84,13 @@ module Vagrant
|
||||||
b.use Builtin::ConfigValidate
|
b.use Builtin::ConfigValidate
|
||||||
b.use Builtin::Call, Created do |env1, b2|
|
b.use Builtin::Call, Created do |env1, b2|
|
||||||
if !env1[:result]
|
if !env1[:result]
|
||||||
b2.use Message, :not_created
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
b2.use Builtin::Call, IsRunning do |env2, b3|
|
b2.use Builtin::Call, IsRunning do |env2, b3|
|
||||||
if !env2[:result]
|
if !env2[:result]
|
||||||
b3.use Message, :not_running
|
b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
b2.use Message, :not_created
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -158,7 +158,7 @@ module Vagrant
|
||||||
Builder.new.tap do |b|
|
Builder.new.tap do |b|
|
||||||
b.use Builtin::Call, Created do |env1, b2|
|
b.use Builtin::Call, Created do |env1, b2|
|
||||||
if !env1[:result]
|
if !env1[:result]
|
||||||
b2.use Message, :not_created
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ module Vagrant
|
||||||
b3.use Builtin::ProvisionerCleanup
|
b3.use Builtin::ProvisionerCleanup
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
b3.use Message, :will_not_destroy
|
b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.will_not_destroy")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -185,7 +185,7 @@ module Vagrant
|
||||||
Builder.new.tap do |b|
|
Builder.new.tap do |b|
|
||||||
b.use Builtin::Call, Created do |env1, b2|
|
b.use Builtin::Call, Created do |env1, b2|
|
||||||
if !env1[:result]
|
if !env1[:result]
|
||||||
b2.use Message, :not_created
|
b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
Loading…
Add table
Reference in a new issue