mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-16 04:48:27 +08:00
12 lines
294 B
Go
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) }
|
|
}
|