mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 18:07:51 +08:00
31 lines
493 B
Go
31 lines
493 B
Go
package eval
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
)
|
|
|
|
var errNonExistentEnvVar = errors.New("non-existent environment variable")
|
|
|
|
func init() {
|
|
addBuiltinFns(map[string]interface{}{
|
|
"has-env": hasEnv,
|
|
"get-env": getEnv,
|
|
"set-env": os.Setenv,
|
|
"unset-env": os.Unsetenv,
|
|
})
|
|
}
|
|
|
|
func hasEnv(key string) bool {
|
|
_, ok := os.LookupEnv(key)
|
|
return ok
|
|
}
|
|
|
|
func getEnv(key string) (string, error) {
|
|
value, ok := os.LookupEnv(key)
|
|
if !ok {
|
|
return "", errNonExistentEnvVar
|
|
}
|
|
return value, nil
|
|
}
|