Add a function to get to the "original" environment with Vagrant
This function only works when used with the official Vagrant installer.
This commit is contained in:
parent
c1508cd893
commit
d8d5a66fa5
|
@ -227,6 +227,22 @@ module Vagrant
|
||||||
requirements: requirements.join(", "),
|
requirements: requirements.join(", "),
|
||||||
version: VERSION
|
version: VERSION
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This allows plugin developers to access the original environment before
|
||||||
|
# Vagrant even ran. This is useful when shelling out, especially to other
|
||||||
|
# Ruby processes.
|
||||||
|
#
|
||||||
|
# @return [Hash]
|
||||||
|
def self.original_env
|
||||||
|
{}.tap do |h|
|
||||||
|
ENV.each do |k,v|
|
||||||
|
if k.start_with?("VAGRANT_OLD_ENV")
|
||||||
|
key = k.sub(/^VAGRANT_OLD_ENV_/, "")
|
||||||
|
h[key] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Default I18n to load the en locale
|
# Default I18n to load the en locale
|
||||||
|
|
|
@ -98,4 +98,23 @@ describe Vagrant do
|
||||||
to raise_error(Vagrant::Errors::VagrantVersionBad)
|
to raise_error(Vagrant::Errors::VagrantVersionBad)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "original_env" do
|
||||||
|
before do
|
||||||
|
ENV["VAGRANT_OLD_ENV_foo"] = "test"
|
||||||
|
ENV["VAGRANT_OLD_ENV_bar"] = "test"
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
ENV["VAGRANT_OLD_ENV_foo"] = "test"
|
||||||
|
ENV["VAGRANT_OLD_ENV_bar"] = "test"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return the original environment" do
|
||||||
|
expect(Vagrant.original_env).to eq(
|
||||||
|
"foo" => "test",
|
||||||
|
"bar" => "test",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue