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:
parent
31a3a3f2e2
commit
1e997f87d7
|
@ -6,7 +6,9 @@ module VagrantPlugins
|
||||||
autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__)
|
autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__)
|
||||||
autoload :CheckVirtualbox, File.expand_path("../action/check_virtualbox", __FILE__)
|
autoload :CheckVirtualbox, File.expand_path("../action/check_virtualbox", __FILE__)
|
||||||
autoload :Created, File.expand_path("../action/created", __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 :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
|
# Include the built-in modules so that we can use them as top-level
|
||||||
# things.
|
# things.
|
||||||
|
@ -23,19 +25,12 @@ module VagrantPlugins
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
# If the VM is created, then we confirm that we want to
|
b2.use Call, DestroyConfirm do |env2, b3|
|
||||||
# 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|
|
|
||||||
if env2[:result]
|
if env2[:result]
|
||||||
b3.use Vagrant::Action::General::Validate
|
b3.use Vagrant::Action::General::Validate
|
||||||
b3.use CheckAccessible
|
b3.use CheckAccessible
|
||||||
else
|
else
|
||||||
env2[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
|
b3.use MessageWillNotDestroy
|
||||||
:name => env[:machine.name])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue