-
Notifications
You must be signed in to change notification settings - Fork 182
Vagrantfile,.gitignore: Maintain state between vagrant runs. #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
STATEFILE = ".vagrant-state" | ||
|
||
if File.exist?(STATEFILE) | ||
File.open(STATEFILE).read.lines.map { |x| x.split("=", 2) }.each { |x,y| ENV[x] = y } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File.open("foo").read
can be written as File.read("foo")
as of 1.9
|
||
def self.up_hook(arg) | ||
unless File.exist?(STATEFILE) # prevent it from writing more than once. | ||
f = File.open(STATEFILE, "w") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also File.write
now, so you could do something like:
data = ENV.map { |x,y| "%s=%s" % [x,y] }.join("\n")
File.write(STATEFILE, data)
@gaurav-dalvi tested this and @dseevr reviewed. I think this is ready for merge. |
LGTM. Thanks @erikh for taking care of this so quickly |
Once the tests pass, we can merge. |
@erikh needs a bumparoo |
Signed-off-by: Erik Hollensbe <[email protected]>
ready for merge |
This patch implements a state tracker for vagrant runs. It does this by saving your current environment to a file called
.vagrant-state
in the CWD. It then restores that state (if it exists) for each run, allowing you to do any vagrant command without worrying about supplying environment variables to control it. On destroy, the file is removed.This is sufficiently advanced ruby, so please do focus on the functionality. Perhaps @dseevr would like to review this one as I know he's more than capable of doing so.