environment_unload hook

This commit is contained in:
Mitchell Hashimoto 2013-02-22 13:54:28 -08:00
parent 3c343c0623
commit 46db50680b
3 changed files with 26 additions and 1 deletions

View File

@ -45,7 +45,13 @@ begin
env.ui.warn(I18n.t("vagrant.general.not_in_installer")) if !Vagrant.in_installer? env.ui.warn(I18n.t("vagrant.general.not_in_installer")) if !Vagrant.in_installer?
# Execute the CLI interface, and exit with the proper error code # Execute the CLI interface, and exit with the proper error code
exit(env.cli(ARGV)) exit_status = env.cli(ARGV)
# Unload the environment so cleanup can be done
env.unload
# Exit with the exit status from our CLI command
exit(exit_status)
rescue Vagrant::Errors::VagrantError => e rescue Vagrant::Errors::VagrantError => e
logger.error("Vagrant experienced an error! Details:") logger.error("Vagrant experienced an error! Details:")
logger.error(e.inspect) logger.error(e.inspect)

View File

@ -379,6 +379,18 @@ module Vagrant
nil nil
end end
# Unload the environment, running completion hooks. The environment
# should not be used after this (but CAN be, technically). It is
# recommended to always immediately set the variable to `nil` after
# running this so you can't accidentally run any more methods. Example:
#
# env.unload
# env = nil
#
def unload
hook(:environment_unload)
end
# Makes a call to the CLI with the given arguments as if they # Makes a call to the CLI with the given arguments as if they
# came from the real command line (sometimes they do!). An example: # came from the real command line (sometimes they do!). An example:
# #

View File

@ -300,6 +300,13 @@ VF
end end
end end
describe "#unload" do
it "should run the unload hook" do
instance.should_receive(:hook).with(:environment_unload).once
instance.unload
end
end
describe "getting a machine" do describe "getting a machine" do
# A helper to register a provider for use in tests. # A helper to register a provider for use in tests.
def register_provider(name, config_class=nil) def register_provider(name, config_class=nil)