elvish/pkg/util/temp_env.go
2019-12-23 20:00:59 +00:00

12 lines
294 B
Go

package util
import "os"
// WithTempEnv sets an environment variable to a temporary value, and returns a
// function for restoring the old value.
func WithTempEnv(name, value string) func() {
oldValue := os.Getenv(name)
os.Setenv(name, value)
return func() { os.Setenv(name, oldValue) }
}