Clean up the actions a bit, move logic into actual middleware.

This is a good idea because in the future it will allow plugins to
properly override these behaviors.
This commit is contained in:
Mitchell Hashimoto 2012-07-28 19:58:10 -07:00
parent 31a3a3f2e2
commit 1e997f87d7
3 changed files with 37 additions and 9 deletions

View File

@ -6,7 +6,9 @@ module VagrantPlugins
autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__)
autoload :CheckVirtualbox, File.expand_path("../action/check_virtualbox", __FILE__)
autoload :Created, File.expand_path("../action/created", __FILE__)
autoload :DestroyConfirm, File.expand_path("../action/destroy_confirm", __FILE__)
autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__)
autoload :MessageWillNotDestroy, File.expand_path("../action/message_will_not_destroy", __FILE__)
# Include the built-in modules so that we can use them as top-level
# things.
@ -23,19 +25,12 @@ module VagrantPlugins
next
end
# If the VM is created, then we confirm that we want to
# destroy it.
message = I18n.t("vagrant.commands.destroy.confirmation",
:name => env[:machine].name)
confirm = Vagrant::Action::Builder.build(Confirm, message)
b2.use Call, confirm do |env2, b3|
b2.use Call, DestroyConfirm do |env2, b3|
if env2[:result]
b3.use Vagrant::Action::General::Validate
b3.use CheckAccessible
else
env2[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
:name => env[:machine.name])
b3.use MessageWillNotDestroy
end
end
end

View File

@ -0,0 +1,16 @@
require "vagrant/action/builtin/confirm"
module VagrantPlugins
module ProviderVirtualBox
module Action
class DestroyConfirm < Vagrant::Action::Builtin::Confirm
def initialize(app, env)
message = I18n.t("vagrant.commands.destroy.confirmation",
:name => env[:machine].name)
super(app, env, message)
end
end
end
end
end

View File

@ -0,0 +1,17 @@
module VagrantPlugins
module ProviderVirtualBox
module Action
class MessageWillNotDestroy
def initialize(app, env)
@app = app
end
def call(env)
env[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
:name => env[:machine].name)
@app.call(env)
end
end
end
end
end